たとえば毎分、Google Chrome拡張機能から別のページにデータを投稿することは可能ですか?誰かがクロームを開くと、毎分私のページに情報が送信されます。回答ありがとうございます。
2 に答える
1
はい、これは非常に可能です。簡単な例:
背景ページ
//These make sure that our function is run every time the browser is opened.
chrome.runtime.onInstalled.addListener(function() {
initialize();
});
chrome.runtime.onStartup.addListener(function() {
initialize();
});
function initialize(){
setInterval(function(){sendData()},60000);
}
function sendData(){
//Assuming data contains the data you want to post and url is the url
$.post(url,data);
}
Manifest.json
投稿する場所のホスト権限をリクエストする必要があります。「 http://www.example.com/postHere.php 」に沿った何か。詳細については、一致パターンを参照してください。
{
"name": "Chrome post test",
"version": "0.1",
"description": "A test for posting",
"manifest_version": 2,
"permissions": [
"http://www.example.com/postHere.php"
],
"background": {
"scripts": ["jquery-1.8.3.min.js","background.js"],
"persistent": true
}
}
于 2013-03-24T17:48:58.923 に答える
1
試してみてくださいsetInterval()
。バックグラウンドページでロジックをラップする必要があります。"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
文字列を実行する場合は、manifest.jsonを追加することを忘れないでください。詳細については、これを参照することをお勧めします。
于 2013-03-24T17:52:45.040 に答える