Jump to content

Determine if .js file has been attached/loaded yet


Axeia

Recommended Posts

Working on a greasemonkey script and I'm trying to remove the onclick from a button that's created via javascript.

Greasemonkey seems to fire before the script loaded, preventing me from manipulating the button.

 

How do I 'wait' for an external javascript to have been loaded so I can let greasemonkey do what it needs to do?

greasemonkey loads last, so you can count on your loaded javascripts to be there. GM handles events a little different, as you're dealing with wrappers rather than the elements themselves.

 

One trick that I've found is to use setTimeout to execute the function that do your business; the scope there should be the real window.

 

setTimeout(function(){ document.getElementById('foo').onclick=function(){} }, 20);

 

If your GM script tried to do something "illegal", it stops silently. I like to console.log (firebug) every few lines to be sure that the whole script is executed.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.