Skip to content

Instantly share code, notes, and snippets.

@ZhihaoLau
Last active August 15, 2016 03:52
Show Gist options
  • Save ZhihaoLau/55639a5a35d65a2999145e72fe245c89 to your computer and use it in GitHub Desktop.
Save ZhihaoLau/55639a5a35d65a2999145e72fe245c89 to your computer and use it in GitHub Desktop.
safari无痕浏览模式下,setItem抛出异常导致程序不能正常运行
// 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