Created
August 12, 2014 13:26
-
-
Save elrrrrrrr/bb03981afeb125d7f432 to your computer and use it in GitHub Desktop.
localstroge hotfix by sofish
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
// 解决隐私模式下 localStorage 不正常问题 | |
;(function() { | |
var KEY = '_localStorage_' | |
, VALUE = 'test'; | |
// 检测是否正常 | |
try { | |
localStorage.setItem(KEY, VALUE); | |
} catch(e) { | |
var noop = function() {}; | |
localStorage.__proto__ = { | |
setItem: noop, | |
getItem: noop, | |
removeItem: noop, | |
clear: noop | |
}; | |
} | |
// 删除测试数据 | |
if(localStorage.getItem(KEY) === VALUE) localStorage.removeItem(KEY); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment