Last active
August 15, 2016 03:52
-
-
Save ZhihaoLau/55639a5a35d65a2999145e72fe245c89 to your computer and use it in GitHub Desktop.
safari无痕浏览模式下,setItem抛出异常导致程序不能正常运行
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cause safari private mode do not support storage | |
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('你的浏览器似乎不支持本地缓存,如果你是Safari用户,请关闭“无痕浏览”模式'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment