Possible duplicate:Dynamically Including jQuery using JavaScript, if not already submitted
I make the site look like google analytics in that I have my users embed some javascript code on their site. My question is: how can I include jQuery in my javascript code snippet?
I already know how to include files using js: How to include a JavaScript file in another JavaScript file?
But how can I make sure that there are no jQuery conflicts?
Gold star for anyone who offers good practices in terms of generating javascript inline code :)
Short answer: you do not.
You should not overlay your users. Google does not do this with analytics, and you should not either. Use only the basic functionality of the java script and write from scratch or copy what you need from other projects (as long as the licenses allow).
Always verify that everything you include is not yet defined:
if(typeof jQuery === "undefined") { // include jQuery }
I suggest using the jQuery no conflict function.
http://uzbekjon.hubpages.com/hub/How-to-use-jQuery_noConflict
Hope this helps
It is impossible to do this without conflicts with user scripts.
Read this discussion to learn how to write code without jQuery: is there an easy way to convert jquery code to javascript?