tags:

views:

32

answers:

2

I am writing a greasemonkey script. The site is using jquery, i need a function in a newer version. In my GM script i have

// @require        http://ajax.microsoft.com/ajax/jQuery/jquery-1.3.2.min.js
...
var $ = unsafeWindow.jQuery;

However after using alert($().jquery); i see it is still the old version. How can i get the newer version in code?

+1  A: 

If you use unsafeWindow.jQuery, you get the site's jQuery. If you use $ without reassigning it, you'll get the jQuery downloaded by Greasemonkey. So just remove the line assigning $.

Uninstall and reinstall the script. If you edit the @require line, it won't take effect until the script is installed again.

interjay
I see the new version in the my folder. However it isnt being applied because the site has jquery already.
acidzombie24
@acidzombie24: Ah, I misread your question. Updated with a hopefully better answer.
interjay
I could swear one of my other scripts did not work when i did not use unsafeWindow.jQuery after using require. weird. accepted.
acidzombie24
A: 

You can use the noConflict option, sample code below:

<script type="text/javascript">
    // get a reference to the old one
    var jq132 = jQuery;
    // free up the $ alias (it becomes version 1.4.2
    jQuery.noConflict();

    // create a new alias for the 1.4.2 version
    var jq142 = $;
    // restore the 1.3.2 version to the $ alias
    $ = jq132;
</script>

If you don't want the 1.3.2 version at all then you can free up both the $ and the jQuery name by calling:

jQuery.noConflict(true);
Felan