'document' undefined in Greasemonkey

Not more than ten minutes ago, I decided to write my first script for Greasemonkey. I have no experience with him. Also, my JavaScript is a bit rusty, as it has been a while since I last wrote the code. But I can not understand why Greasemonkey gives me this error:

Line: 9 Char: 2 Error: 'document' is undefined Code: 800A1391 Source: Microsoft JScript runtime error 

Here is my script:

 // ==UserScript== // @name Easier WatchSeries // @namespace n/a // @include http://www.watch-series.com/episode/* // ==/UserScript== function thing() { document.body.setAttribute('onload', show_links(document.getElementById('idepisod').value)); } thing(); 

All I want to do is add the onLoad attribute to the body tag. I get this error when I go to "Manage new user scripts" → "Edit". In addition, the script does nothing, obviously something is wrong.

I am running Firefox 3.6.13.

+4
source share
1 answer

A few things:


Combining all this, your script will become:

 // ==UserScript== // @name Easier WatchSeries // @namespace n/a // @include http://www.watch-series.com/episode/* // @include http://watch-series.com/episode/* // ==/UserScript== function my_func() { try { unsafeWindow.show_links(document.getElementById('idepisod').value); } catch (zError) { alert (zError); //-- Use console.log() in place of alert(), if running Firebug. } } window.addEventListener ("load", my_func, false); 
+5
source

Source: https://habr.com/ru/post/1337249/


All Articles