javascript - 互联网浏览器 : Official status of userData behavior?

标签 javascript css internet-explorer

我在使用 userData 时遇到了问题IE9 中的行为,当遇到不支持 Web 存储规范的 IE 版本时,我会使用它。

具体来说,执行 .save() 函数时似乎没有保存值(事实上,C:\Users\USERNAME\AppData\Roaming\Microsoft 中甚至没有 userData 文件夹\Internet Explorer\UserData ,也不是在执行 .save() 时创建的)。

我做了一些研究,从各种网站上的一些评论中得出的共识是,它似乎在 IE9 中被禁用了。

是否有某种官方声明表达了这一点?如果是这样,有没有办法测试给定的 IE 版本是否支持它(无需浏览器嗅探)?

最佳答案

经过一些研究,我似乎(大部分)找到了问题的答案。

Is there some sort of official statement expressing this ("this" meaning that userData is no longer supported in IE9)?

由于我找不到任何官方声明确认在 IE9 中停止支持此特定行为,因此网络上的评论和投诉就足够了:IE9 不支持 userData 行为。此外,no behaviors and HTCs are supported in IE10 .

Is there a way to test whether a given IE version supports it (the userData behavior) (without browser sniffing)?

对于不支持 userData 的 IE10 和早期版本的 IE,可以检查附加行为的元素上是否存在 addBehavior() 成员函数:

//Assuming "element" has had the userData behavior associated with it through CSS
if(element.addBehavior)

处理 IE9 有点棘手,因为存在与 userData 行为相关的方法,并且在正确使用时不会抛出异常。

幸运的是,我们可以利用数据存储机制与每个具有 userData 行为的元素接收的 XMLDocument 成员之间的关系。由于此特定成员表示调用 save() 时要存储到磁盘的文件,因此应该在每次调用 时更新 element.XMLDocument.xml元素.addAttribute(键,值)。如果不是,那么我们可以假设不支持 userData:

//Assuming "element" has had the userData behavior associated with it through CSS
if(element.addBehavior)
{
    element.addAttribute("test", "");

    //If the to-be-saved XML was updated with the attribute we just added
    if(element.XMLDocument.xml.indexOf("test") !== -1) 
    {
        //userData behavior is supported
    }
    else
    {
        //userData behavior is not supported
    } 
}

来自 MS 的官方声明确认了这种支持的下降,以及一种在不添加虚拟属性的情况下确定完整 userData 行为支持的方法仍然值得赞赏。如果您遇到其中任何一个,请随时发布。

关于javascript - 互联网浏览器 : Official status of userData behavior?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13481817/

相关文章:

javascript - 从 php 到 select2 的 json 响应不渲染

javascript - 限制输入字段上图像的宽度和高度

css - 如何创建网格/平铺 View ?

kendo-grid - 仅当省略号处于事件状态时才显示剑道工具提示

javascript - IE6/7/8 内存不足?

javascript - Node JS - 从先前的实例或状态清除超时

javascript - 如何获得 2 个日期范围数组之间的差异?

javascript - 菜单卡住,无法点击

python - 无法通过 Selenium WebDriver python 绑定(bind)启动 Internet Explorer

javascript - JQuery .load() 在 Internet Explorer 中不起作用