Onload event does not fire in chrome content script

I am using content script in my Chrome extension. Content scripts are entered in "document_start".

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

I run the above code in the content script, but when I load the page, the onload event does not fire.
Is there something wrong?

+7
source share
2 answers

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);} 
+3
source

Works great. To check if console.log running or not, on the onload windows event.

Launch ( Load ) the / Script page in Chrome.

Right click and select Inspect element .

Click the Console tab .

In the console field, you will see " window onload event fired. "

Screen shot:

enter image description here

-4
source

All Articles