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);
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.
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.
Try using: unsafeWindow.myFunction();
More details and info - http://wiki.greasespot.net/UnsafeWindow
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With