私はポップアップのデータをフォームに塗りつぶす拡張子を作成しようとしていますが、「背景」と「コンテンツ」ファイルの使用に関してはちょっと混乱しています。私が必要とは思わない。ここに私のコードは次のとおりです。popup.htmlのデータをフォームに入力してください
マニフェスト:
{
"name": "Browser action for Form",
"description": "Fill a form with data from the popup",
"version": "1.0",
"permissions": [
"tabs", "http://*/*", "https://*/*"
],
"browser_action": {
"default_title": "Form Test",
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["https://the-site-with-a-form.com/*"],
"js": ["jquery-3.1.1.min.js", "content.js"]
}
],
"manifest_version": 2
}
popup.html
<!doctype html>
<html>
<head>
<title>Form</title>
<script src="popup.js"></script>
</head>
<body>
<form>
<textarea id="txtArea"></textarea>
<input type="button" id="btn1" value="Run">
</form>
</body>
</html>
popup.js
function click(){
var text = document.getElementById("txtArea")
chrome.tabs.sendMessage(
tabs[0].id,
{from: 'popup', subject: 'DOMInfo',data1: text});
}
content.js
chrome.runtime.onMessage.addListener(function (msg, sender, response) {
if ((msg.from === 'popup') && (msg.subject === 'DOMInfo')) {
//Fill the form with the data of the popup
document.getElementById("The textbox from the form").value = msg.data1;
}
});
コードで何が間違っていますか? ありがとう!
感謝を固定 "タブ" とpopup.jsです!確かに問題は "sendMessage"の "tabs"引数にあり、それを修正しました: var activeTab = tabs [0]; chrome.tabs.sendMessage(activeTab.id、{"message": "s" ........ が今すぐ動作します!ありがとうございました! – 123345566i
あなた自身の解決策がある場合は、別の回答として投稿してください。 – Xan