Skip to content Skip to sidebar Skip to footer

Why Does Jquery Load Twice In My Greasemonkey Script

for some reason my Firefox4+GreaseMonkey Script loads jQuery twice. I copy'n'pasted the following snippet, the 'test' alert shows twice. Regards var $; // Add jQuery (function(){

Solution 1:

This is probably because the target page is loading frames or iframes.

Add these lines to the top of the code-portion of your script:

if (window.top != window.self)  //-- Don't run on frames or iframesreturn;

Also, if you are just using FF + GM, don't bother with all that rigamarole to load jQuery. GM now works with the later jQuery versions.

Just add a line like:

// @require http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js

into your script's metadata block. jQuery will be copied once onto your local machine and run from there -- eliminating what can sometimes be a few seconds delay in your script's runtime.

And such scripts can run in Chrome, if you use one of the GM-emulating extensions like TamperMonkey.

Post a Comment for "Why Does Jquery Load Twice In My Greasemonkey Script"