IE8和localStorage支持 [英] IE8 and localStorage support
本文介绍了IE8和localStorage支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不确定IE8是否完全支持localStorage。
但是我使用以下方法来检测
function supports_html5_storage()
{
try {
在窗口&&中返回'localStorage' window ['localStorage']!== null;
}
catch(e){
return false;
}
}
现在IE在窗口中为'localStorage'返回true / p>
但是窗口返回undefined ['localStorage']
所以我应该更新这个方法还是IE8确实有本地存储支持?
解决方案
您可以尝试设置和读取localStorage。
如果已禁用Cookie或您正在使用file:protocol,某些浏览器会返回安全错误
。
function hasStorage(){
try {
localStorage.setItem('test','7');
if(localStorage.getItem('test')==='7'){
localStorage.removeItem('test');
返回true;
}
}
catch(呃){}
返回false;
}
警告(hasStorage())
I am not sure if IE8 fully supports localStorage. But I use the following method to detect
function supports_html5_storage()
{
try {
return 'localStorage' in window && window['localStorage'] !== null;
}
catch (e) {
return false;
}
}
Now IE returns true for 'localStorage' in window
But returns undefined for window['localStorage']
So should I update this method OR does IE8 indeed have local storage support ?
解决方案
You can try to set and read localStorage.
Some browsers return a security error if cookies are disabled or you are working with file: protocol.
function hasStorage(){
try{
localStorage.setItem('test', '7');
if(localStorage.getItem('test')=== '7'){
localStorage.removeItem('test');
return true;
}
}
catch(er){}
return false;
}
alert(hasStorage())
这篇关于IE8和localStorage支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文