【发布时间】:2011-08-04 06:31:19
【问题描述】:
就开发 chrome 扩展而言,我是新手。
我正在测试一个扩展。在这个我有一个背景页面和选项页面。在选项页面中,我将用户输入的密码存储在本地存储中,我想在点击浏览器图标的背景页面中检索该密码。
我的选项页面是:
<html>
<head>
<title>Options for Password</title>
<script>
function savePassword()
{
window.localStorage.setItem('password', txtPassword.value);
}
</script>
</head>
<body >
<h1>Enter Password</h1>
<input type='password' name='txtPassword' id='txtPassword'/>
<br />
<button onclick='savePassword();'>Save</button>
<br />
</body>
</html>
而我的后台页面是:
<html>
<head>
<script>
// Called when the user clicks on the browser action.
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null, {code:"alert('password from tab:'+window.localStorage.getItem('password'));getfeedback_dialog_submitButton.setAttribute('onclick', 'if(gettext.value==\'"+window.localStorage.getItem(password)'+"\'){document.body.removeChild(getfeedbackcontainer);document.body.removeChild(getfeedbackoverlay);}');"});
});
</script>
</head>
</html>
当我通过选项页面保存密码然后点击浏览器操作时,我会收到警报 password from tab:null。
我很困惑如何检索存储在本地存储中的值?
【问题讨论】:
标签: google-chrome google-chrome-extension local-storage