美文网首页Html5专题
html5中localStorage 在苹果设备上总结

html5中localStorage 在苹果设备上总结

作者: lxt410725 | 来源:发表于2017-09-24 20:27 被阅读55次

            前端时间做开发的时候,用到localStorage,但是在苹果设备上出现了问题,就是在苹果设备上的浏览器中无法存储,最后花了点精力,找到了问题所在——浏览器的无痕模式,因为一般默认的是无痕模式,在无痕模式下,localStorage属于禁用的状态,所以出现了问题。

    if (typeof localStorage === 'object') {

    try {

    localStorage.setItem('localStorage', 1);

    localStorage.removeItem('localStorage');

    } catch (e) {

    Storage.prototype._setItem = Storage.prototype.setItem;

    Storage.prototype.setItem = function() {};

    alert('Your web browser does not support storing settings locally. In Safari, the most common cause of this is using "Private Browsing Mode". Some settings may not save or some features may not work properly for you.');

    }

    }

    这样就可以进行检测,判断当前的浏览器是否允许用localStorage


    相关文章

      网友评论

        本文标题:html5中localStorage 在苹果设备上总结

        本文链接:https://www.haomeiwen.com/subject/zkllextx.html