Why does jQuery load twice in my GreaseMonkey Script

前端 未结 1 1447
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-05 01:31

for some reason my Firefox4+GreaseMonkey Script loads jQuery twice. I copy\'n\'pasted the following snippet, the \"test\" alert shows twice.

Regards

         


        
相关标签:
1条回答
  • 2021-01-05 02:08

    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 iframes
        return;
    


    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.

    0 讨论(0)
提交回复
热议问题