Why is script.onload not working in a Chrome userscript?

后端 未结 1 1660
感情败类
感情败类 2021-01-13 10:27

I want to load another script file, in a site, using a userscript. But, the js.onload event doesn\'t work correctly.

The userscript file:



        
1条回答
  •  情书的邮戳
    2021-01-13 10:42

    Never use .onload, .onclick, etc. from a userscript. (It's also poor practice in a regular web page).

    The reason is that userscripts operate in a sandbox ("isolated world"), and you cannot set or use page-scope javascript objects in a Chrome userscript or content-script.

    Always use addEventListener() (or an equivalent library function, like jQuery .on()). Also, you should set load listeners before adding

提交回复
热议问题