2013-03-24 27 views

回答

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」的線。有關更多信息,請參見Match Patterns

{ 
    "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 
    } 
} 
1

嘗試setInterval()。你應該把你的邏輯放在你的背景頁面中。如果您執行字符串,請不要忘記在您的manifest.json中添加"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"。欲瞭解更多,你可能想瀏覽this