入力値を取得し、それをvarにしてウェブページの値を変更しようとしています。私はそれが正しい方法であるかわからないが、私が知っている限りは:/私はちょっと私の拡張入力からページを埋めるオートフィラーを作る必要があります。私はそれが私のinput.valueを直接検索するときにしようとしましたが、それは常にnullを表示し、私もlocalStorageで自分の入力を保存しようとしました...しかし、それは仕事をしない:(私はすべてを投稿しようとしたとき。これは愚かな質問であれば、私は 申し訳ありませんのlocalStorageに私の入力を保存するが、私はちょうどそれが仕事を得るカント:(クロムエクステンション - 入力値を取得するには
マニフェストファイルとき:
{
"manifest_version" : 2,
"name": "sAVING iNPUT",
"version": "1.0",
"description" : "Click something pls",
"version" : "1.0",
"permissions" : ["<all_urls>"],
"browser_action" : {
"default_popup" : "popup.html"
}
}
Popup.htmlファイル:
<!DOCTYPE html>
<html>
<head><title> activity</title></head>
<body>
<div>
<div>
E-Pasts
<input type="text" name="epasts" id="epasts"></input>
</div>
<button id="ielogoties" aonClick="saveInput()" > login </button>
</div>
<script src="popup.js">
function saveInput(){
localStorage.setItem("epastss", document.getElementById("epasts"));
}
</script>
</body>
</html>
ポップアップファイル:
function injectTheScript() {
chrome.tabs.query({active : true, currentWindow:true},function(tabs){
chrome.tabs.executeScript(tabs[0].id,{file: "content_script.js"});
});
}
document.getElementById("ielogoties").addEventListener
("click",injectTheScript);
content_script.jsファイル:私はボタンを押したときに
var drepasts = document.getElementById("email");
var epasts = localStorage.getItem("epastss")
drepasts.value= epasts;
alert("hehejr");
localStorage.removeItem("epasts");
は今、私はこのエラーを取得しています:それは、次のコンテンツセキュリティポリシーの指示に違反しているため
はインラインイベントハンドラを実行することを拒否: " script-src 'self' blob:ファイルシステム:chrome-extension-resource: "インライン実行を有効にするには、 'unsafe-inline'キーワード、ハッシュ( 'sha256 -...')、またはnonce( 'nonce -...')のいずれかが必要です。
その私がダムのミスを、それはまだヌルとして表示:( – TheProfesor
@TheProfesorあなたがしようとしていますinput要素、またはその値を保存するには?値を保存するには、 'setItem'の値を' document.getElementById( "epasts")。value'に変更する必要があります。 – freginold