Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get greasemonkey to call a function on a page after it loads

I have a very simple greasemonkey script that I want to call an already existing javascript function on the page. I've read the documentation and nothing seems to work

window.setTimeout(function() {      alert('test') // This alert works, but nothing after it does     myFunction() // undefined     window.myFunction() // undefined     document.myFunction() // undefined }, 1000); 
like image 945
Asa Ayers Avatar asked Jan 14 '09 15:01

Asa Ayers


People also ask

How do you call a function from another script in HTML?

The first method is to call the JavaScript function in HTML. For this, you have to create a function then define this function either in the head section or body section of the HTML document. You can either create a link or a button and then an onclick() event is associated with them in order to call this function.

Can you call a function in a script?

Short answer: Yes. As long as you load the first script containing the function first, you can call the function anywhere, as long as it's loaded first.


1 Answers

Try using: unsafeWindow.myFunction();

More details and info - http://wiki.greasespot.net/UnsafeWindow

like image 101
Maiku Mori Avatar answered Sep 20 '22 08:09

Maiku Mori