admin管理员组文章数量:1386669
Could any one help me,to find out my problem.I have set my website as chrome extension.When I install the extension,it navigates to a popup window asking user name and password along with a login button. But when I tried to alert the username entered by the user in javascript,it is not working.Anyone please help me.What would be the reason? Here is my 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": "Test Extension",
"default_icon": "calpine_not_logged_in.png"
},
"permissions": [
"*://blog.calpinetech/test/index.php",
"alarms",
"notifications"
],
"web_accessible_resources": [
"/icon_128.png"]
}
Here is my code that creates a pop up window on installation
chrome.windows.create({url : "test.html"});
here is my test.html
<html>
<head>
<script type="text/javascript">
function log(){
var uname=document.getElementById('name');
alert(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()"/>
<p id="pp"></p>
</form>
</body>
</html>
Could any one help me,to find out my problem.I have set my website as chrome extension.When I install the extension,it navigates to a popup window asking user name and password along with a login button. But when I tried to alert the username entered by the user in javascript,it is not working.Anyone please help me.What would be the reason? Here is my 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": "Test Extension",
"default_icon": "calpine_not_logged_in.png"
},
"permissions": [
"*://blog.calpinetech./test/index.php",
"alarms",
"notifications"
],
"web_accessible_resources": [
"/icon_128.png"]
}
Here is my code that creates a pop up window on installation
chrome.windows.create({url : "test.html"});
here is my test.html
<html>
<head>
<script type="text/javascript">
function log(){
var uname=document.getElementById('name');
alert(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()"/>
<p id="pp"></p>
</form>
</body>
</html>
Share
Improve this question
asked Dec 2, 2013 at 6:19
user1991user1991
3213 gold badges8 silver badges17 bronze badges
2 Answers
Reset to default 5The reason it is not working is that test.html
is opened as a "view" of your extension and the Content Security Policy (CSP) prevents inline scripts and inline event-binding from being executed.
You should move the code and the event-bindings to an external JS file.
In test.html:
<html>
<head>
<script type="text/javascript" src="test.js"></script>
</head>
<body>
...
<input type="button" id="login" value="Log In" />
...
</body>
</html>
In test.js:
window.addEventListener('DOMContentLoaded', function() {
var login = document.querySelector('input#login');
login.addEventListener('click', function() {
// ...do stuff...
});
});
You have to pick up value of the input field:
var uname = document.getElementById('name').value;
本文标签: javascriptAlert is not working in pop up window in chrome extensionStack Overflow
版权声明:本文标题:javascript - Alert is not working in pop up window in chrome extension - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744529811a2610963.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论