Javascript 为什么我能';无法在ios9门户网页上获取本地存储?
在safari(ios9,门户网页)中未启用cookie时,我想用cookie覆盖本地存储,但在Javascript 为什么我能';无法在ios9门户网页上获取本地存储?,javascript,safari,local-storage,Javascript,Safari,Local Storage,在safari(ios9,门户网页)中未启用cookie时,我想用cookie覆盖本地存储,但在window.localStorage中得到null 我试图通过对象定义localStorage.defineProperty(窗口,'localStorage',{}),但我得到了一个错误:TypeError:试图更改unconfigurable属性的可配置属性 这就像在safari中运行Object.defineProperty(窗口'localStorage',{configurable:fal
window.localStorage中得到null
我试图通过对象定义localStorage.defineProperty(窗口,'localStorage',{})
,但我得到了一个错误:TypeError:试图更改unconfigurable属性的可配置属性
这就像在safari中运行Object.defineProperty(窗口'localStorage',{configurable:false,value:null})
。然后我就无法获取本地存储或覆盖它了
你可以在你的旅行中运行这个
Object.defineProperty(window, 'localStorage', {configurable: false, value: null}).
然后,我试过这样做,但没有效果
Object.defineProperty(window, 'localStorage', {configurable: true, value: {}). // TypeError: Attempting to change configurable attribute of unconfigurable property.
localStorage.setItem = function(){} // TypeError: null is not an object (evaluating 'localStorage.setItem = function(){}').
我怎样才能修好它?即使使用proto和on
我在ios9门户网页中发现了这个问题。但是,您可以在任何Safari浏览器上使用
Object.defineProperty(窗口'localStorage',{configurable:false,value:null})复制它。
您试图用一个空白对象替换localStorage API。如果您可以这样做,那么它将破坏页面中的本地存储,而不是清空存储的数据
要重置它,请使用
localStorage.clear()代码>我为我的英语不好道歉,我的意思是“覆盖”而不是“重置”,我想用cookie覆盖本地存储