【发布时间】:2013-11-29 09:12:28
【问题描述】:
我已经开发了一个网站并设置为 google chrome 扩展程序。我需要的是,当我安装我的扩展程序时,应该在一个新窗口上打开一个弹出窗口,询问用户名和密码,并且必须将此用户名存储在应该可以在 chrome 扩展中访问的本地存储。我该怎么做,请帮助我。 这是我的 manifest.json
{
"name": "Calpine Extension",
"version": "1.0",
"description": "Log on to calpinemate",
"manifest_version": 2,
"browser_action": {
"default_icon": "icon_128.png"
},
"background": {
"persistent": false,
"scripts": ["background.js"]
},
"browser_action": {
"default_title": "Calpine Extension",
"default_icon": "calpine_not_logged_in.png"
},
"permissions": [
"*://blog.calpinetech.com/test/index.php",
"alarms",
"notifications"
],
"web_accessible_resources": [
"/icon_128.png"]
}
这是我在 background.js 中弹出的代码
chrome.windows.create({url : "test.html"});
这是我在 chrome.runtime.onInstalled.addListener() 里面写的。
这是我的 test.html
<html>
<head>
<script type="text/javascript">
function log(){
var uname=document.getElementById('name');
alert(uname);
//window.localStorage.setItem('uname', $("input[type='username']").val());
//alert(localStorage.uname);
}
</script>
</head>
<body>
<form name="userinfo" id="userinfo">
username :
<input id="name" type="text" name="username"/><br><br>
password :
<input type="password" name="password"/><br><br>
<input type="button" value="Log In" onClick="log()"/>
</form>
</body>
</html>
现在我需要的是,当用户启用我的扩展程序时,必须在新窗口中打开一个弹出窗口,询问用户名和密码。当他输入用户名和密码时,用户名必须存储在本地存储中,可以从chrome 扩展。我该怎么做?请帮帮我。
【问题讨论】:
标签: javascript html google-chrome-extension popupwindow