【发布时间】:2017-11-19 01:59:40
【问题描述】:
我想从 fill.js 加载值,当点击扩展 popup.html 中的锚链接时,它将自动填充具有字段的远程页面上的表单字段#user + #pw 的 ID。这是我目前在我的扩展中拥有的,但我不确定它是否缺少清单文件中的某些内容,或者是否需要 back.js。
fill.js
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.action === "fillFields") {
$("#user").val("name@email.com")
$("#pw").val("pass123")
}
});
popup.js
$("#fill").on("click", function(){
chrome.runtime.sendMessage({
action: 'fillFields'
});
});
popup.html
<!DOCTYPE html>
<html>
<head>
<title>Autofill</title>
<script src="jquery.js"></script>
<script src="popup.js"></script>
</head>
<a href="#" id="fill">Fill</a>
</body>
</html>
manifest.json
{
"manifest_version": 2,
"name": "Autofill",
"description": "",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_title": "Autofill",
"default_popup": "popup.html"
},
"permissions": [
"tabs",
"http://*/*",
"https://*/*"
]
}
远程表单域
<input name="user" type="text" id="user">
<input name="pw" type="text" id="pw">
【问题讨论】:
标签: jquery google-chrome-extension browser-action