0
我想用localStorage
来保存和使用数据。我可以保存和使用数据,但是当我在chrome.tabs.executeScript
中使用localStorage
时,localStorage
始终为空......为什么?localStorage在chrome.tabs.executeScript中不起作用?
我的代码
chrome.tabs.executeScript({ code:
'document.getElementById(":2k.en").onclick = function(){
alert(localStorage.getItem("Message"));
document.getElementById(":2i").value = localStorage.getItem("Token");
document.getElementById(":2k.jl").textContent = "it is OK";
}'
});
谢谢!
我猜你正在使用内容脚本;我的扩展程序有同样的问题。解决方法是使用'chrome.storage',参见[here](http://stackoverflow.com/questions/3598669/cookie-or-localstorage-with-chrome-extensions/15466494#15466494)进行讨论 –
谢谢你的支持答案,你可以给我一些示例代码(如如何在bankgroud.js中设置以及如何获取content_script)?我红色[链接](https://developer.chrome.com/extensions/storage.html),我试过了,它不工作....... – user2262304
有一些有用的例子[这里]( https://developer.chrome.com/extensions/storage)。这有帮助吗? –