# Thursday, February 05, 2009

Make JQuery and Prototpye coexist and play together with a GreaseMonkey User Script

I've been playing with Greasemonkey scripts recently - for Redbubble.com, and wanted to use JQuery with GreaseMonkey.  This is pretty well documented, but I discovered an incompatibility with my script and the host site, as it uses the Prototype Javascript library (must admit I didn't know much about it).

Prototype (like JQuery) uses the $ notation, and so by default any GreaseMonkey User Script loaded will hijack the $ object, meaning that stuff on the original site may stop working.

I thought I was sunk but it turns out JQuery just gets better, and it can gracefully give back control of the $ to whichever library originally loaded it.  Just call..

jQuery.noConflict();

You then have to use jQuery instead of $ (e.g. jQuery("#myID") instead of $("#myID") ), but hey - that's a small price to pay when the alternative is rewriting the whole thing long-hand.

posted on Thursday, February 05, 2009 9:14:44 AM (AUS Eastern Daylight Time, UTC+11:00)  #    Comments [0]
Related posts:
Use SQL Server Trusted Connections with ASP.NET on Windows 2003 without impersonation
Web Visitors vs Users, Impatient vs Bored and how they affect Website Change Management
Coder T-Shirts from Geek Casuals
Using JQuery with DotNetNuke 4.x
ASPNETCOMPILER The Target Directory could not be deleted. Please delete it manually or choose a different target - SubVersion
10 Essential Checks before releasing a Web Site
Comments are closed.