我一直在花费我的最后三天试图获得此项工作,因此请不要回复链接到Chrome API或类似的东西。我正在开发一个与mySql数据库通信的Chrome扩展,以获得用户最喜欢的网站,以及每个网站的登录名/密码(比如说Facebook的fbuser fbpass,谷歌的gguser ggpass ... )带有标签的Chrome扩展程序
所以扩展的目标是要打开一个新标签将每一个网站,并做登录。
我配合建立与数据库通信,我可以成功地打开新标签页与网站,但我堆放在插入用户名和各网站上的密码。我的问题是我不能使用document.getElementsById('input')...因为它返回我的弹出窗口中的元素,而不是在网页上。
所以,我读过有关chrome.tabs.executeScript(),和我想要使用它(似乎这就是我需要用来访问网页的DOM)。
所以我使用的是一样的东西:
chrome.tabs.create({"url": web[i],"selected":false},function(tab) {
chrome.tabs.executeScript(tab.id, {file:"write.js"}, function(){
});
});
与 “write.js” 必须做的自动填充。
所以从这里开始我的问题:
我有一个“警报(”我的“);” write.js中的消息,并且它从不显示(所以函数的其余部分从未被调用过)。 (我在互联网上发现了这个函数“write.js”)。
在这里,我会后我的弹出HTML,清单和JS的部分,也许我有,因为我已经试过了我见过的大多数的例子,而不是为我工作在那里改变一些东西。
manifest.json的:
{
"name": "MyExtension",
"version": "1.0",
"description": "My chrome extension",
"icons":{
"128":"icon_128.png"
},
"browser_action": {
"default_icon": "icon.png",
"popup": "consulta_empleados.html"
},
"permissions": [
"http://*/*",
"https://*/*"
]
}
consulta_empleados.html(弹出):
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Consulta Registro con AJAX</title>
<script src="ajax.js"></script>
</head>
<body>
<form name="form1" method="post" >
<label>
<div align="center">Email<br>
<input type="text" name="email" id="email">
</div>
</label>
<p align="center">
<label>
<input type="submit" name="open" id="open" value="Log In" onClick="runScript()">
</label>
</p>
</form>
<div id="resultado"></div>
<div id="prova"></div>
</body>
</html>
文件ajax.js:
function runScript(){
...
//here I fill a vector with the usernames, the websites and the passwords from the data coming from my database. var num is the number of websites
...
var i=0;
while(i<num){
chrome.tabs.create({"url": web[i],"selected":false},function(tab) {
chrome.tabs.executeScript(tab.id, {file: "write.js"}, function(){
});
});
i++;
}
}
write.js:
function write() {
...
alert("I'm in");
...
}
write();
在此先感谢。
您是否尝试过使用内容脚本,而不是'executeScript'?值得一试。如果它不起作用,请告诉我 - 我会尝试调试您的扩展。 –