Leslie Wu
Leslie Wu

Reputation: 770

window onload event not fired in chrome content script

I use content script in my Chrome extension. content scripts are injected at "document_start".

window.onload = function() {console.log("window onload event fired.");}

I run the above code in content script, but when I load a page, the onload event is not fired.
Is there anything wrong?

Upvotes: 9

Views: 11678

Answers (2)

Baalu
Baalu

Reputation: 243

Check with this Code

if (window.attachEvent) {window.attachEvent('onload', your_function);}
else if (window.addEventListener) {window.addEventListener('load', your_function, false);}
else {document.addEventListener('load', your_function, false);}

Upvotes: 3

Ritesh Kumar Gupta
Ritesh Kumar Gupta

Reputation: 5191

It's working perfectly.In order to check whether the console.log is fired or not on windows onload event.

Run(Load) the Page/Script in Chrome.

Right click and select Inspect element.

Click on Console tab.

You will see "window onload event fired." on console box.

Screen Shot:

enter image description here

Upvotes: -2

Related Questions