Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.