chrome extension script is loading twice even more on some pages
Posted
by
Youhan
on Stack Overflow
See other posts from Stack Overflow
or by Youhan
Published on 2012-10-30T22:44:52Z
Indexed on
2012/10/30
23:00 UTC
Read the original article
Hit count: 190
google-chrome-extension
this is my background.js file
chrome.tabs.onUpdated.addListener(function(tabId,info, tab) {
var sites =new Array('site2','site1');
var url=tab.url;
var siteFlag=0;
for(var i in sites) {
var regexp = new RegExp('.*' + sites[i] + '.*','i');
if (regexp.test(url)) {siteFlag=1;}
};
if(siteFlag==1){
chrome.tabs.executeScript(tabId, {file:"contentscript.js"});
chrome.tabs.executeScript(tabId, {file:"jquery.js"});
chrome.tabs.insertCSS(tabId,{file:"box.css"});
}
});
In the contentscript.js I simply run a popup box.
$(document).ready(function () {
function popup() {...}
if (window.addEventListener)
{
window.addEventListener('load', popup(), false);
}
else if (window.attachEvent)
{
window.attachEvent('onload', popup());
}
});
There are some pages that there are one popup-box and there are pages that two or even more
what is the problem?
© Stack Overflow or respective owner