如何在不单击的情况下启用chrome扩展。
我每次重新加载页面时都需要从我的扩展中执行某个功能(没有点击)是否有办法实现。
我的代码包含on click方法
chrome.extension.onMessage.addListener(function(request, sender) {
if (request.action == "getSource") {
message.innerText = request.source;
}
});
function onWindowLoad() {
var message = document.querySelector('#message');
chrome.tabs.executeScript(null, {
file: "getPagesSource.js"
}, function() {
// If you try and inject into an extensions page or the webstore/NTP you'll get an error
if (chrome.extension.lastError) {
message.innerText = 'There was an error injecting script : \n' + chrome.extension.lastError.message;
}
});
}
window.onload = onWindowLoad;
和
chrome.extension.sendMessage({
action: "getSource",
source: started(document)
});
要包含jQuery:
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
/*all your normal JavaScript (or include as link)*/
</script>
</head>
只使用纯JavaScript,您可以使用:
window.onload = function(){/*your JavaScript code*/};
只有该函数中的代码才会立即执行。
在jQuery中,您可以在$(document).ready(function(){
中加载页面时包装您想要执行的代码,例如:
$(document).ready(function(){
/*code goes here*/
});
$(document).ready()
检查页面加载到何时具有足够的功能。