Sim*_*hke 4 javascript internet-explorer local-storage modernizr
我正在处理客户端问题,其中Modernizr意外地检测不到localStorage
Internet Explorer 9中对象的支持.我的页面正确使用HTML 5 doctype(<!DOCTYPE html>
)和开发人员工具报告页面具有IE9的浏览器模式和文档IE9标准的模式,所以我希望这个工作.
我已调试到Modernizr中的以下try
/ catch
块,并发现一旦localStorage
访问该对象就会抛出JavaScript错误.
tests['localstorage'] = function() {
try {
localStorage.setItem(mod, mod);
localStorage.removeItem(mod);
return true;
} catch(e) {
return false;
}
};
Run Code Online (Sandbox Code Playgroud)
在某些机器上,JavaScript错误的消息是The system cannot find the file specified.
.在其他情况下它只是Invalid argument.
和Internet Explorer阻止错误前5分钟.
是什么导致访问该localStorage
对象在Internet Explorer上抛出错误?
我已经发现,如果最低级别的子域与保留的设备名称之一匹配,如Internet Explorer 上的文件掩码和文件名属性的限制所述,则访问该localStorage
对象将引发错误.
此问题可能发生,因为内部Internet Explorer在访问localStorage
对象时尝试使用保留的设备名访问文件系统以满足Storage
对象初始化步骤.
这当然是非常边缘的情况下,但如果你的网页是来自于它的最低级子域名正是任何一个服务器con
,prn
,aux
,clock$
,nul
,com1
,com2
,com3
,com4
,com5
,com6
,com7
,com8
,com9
,lpt1
,lpt2
,lpt3
,lpt4
,lpt5
,lpt6
,lpt7
,lpt8
,或lpt9
(例如http://prn.example.com
)那么这就是你看到这个问题的原因.
在这种情况下选择不是保留设备名称的较低级别子域解决了该问题.