By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,701 Members | 2,006 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,701 IT Pros & Developers. It's quick & easy.

<SCRIPT> in HTML / Multiple js frameworks

P: 34
Is there any way to dynamically change what script included in the HTML?

Expand|Select|Wrap|Line Numbers
  1. <span id="changeit"><script src="test1.js"></script></span>
  2.  
  3. <input type="button" onClick="document.getElementById('changeit").innerHTML="<script src="test2.js"></script>" />
  4.  
Is there anyway for the <script> include to take affect?

I am doing to get around the fact that i am using two different js frame works.
jQuery and Mootools. There seems to be a conflict.
So, when the user clicks the button I want to unload JQuery and load Mootools.
Jan 23 '08 #1
Share this Question
Share on Google+
7 Replies


acoder
Expert Mod 15k+
P: 16,027
Give the script tag an id and change its src:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("scriptID").src="newsrc.js";
Jan 23 '08 #2

P: 34
Does the browers load the <script src="..."> file at the beginning when the page loads? Once the <script> file is read by the browers, does it read it again?
Jan 23 '08 #3

100+
P: 428
javascripts don't disappear when you change or remove the script element that originally loaded them.

You would have to write a routine that deletes every method and property created by that particular script- kind of like removing the first hundred peas that were mixed into a kettle of pea soup.

You have several choices-
find the conflicts and rewrite the libraries, or find a library that does everything you want, or write your own code.
Jan 23 '08 #4

P: 7
As I recall, the Mootools site is designed such that you can select exactly which function/effects you need and download a .js file that contains only those functions. Have you tried doing that and limiting the functions to exactly what you need on that page (for example, by only selecting the fancy rollover button script or whatever it is you're using)?

In general, any of the big javascript frameworks such as Mootools, Yahoo UI, and Prototype, are meant to be used as THE single framework and are going to be incompatible with one another. I suggest that you determine which framework does the most out of what you want, use that one, and then write the rest of the script you need yourself.
Jan 23 '08 #5

acoder
Expert Mod 15k+
P: 16,027
javascripts don't disappear when you change or remove the script element that originally loaded them.

You would have to write a routine that deletes every method and property created by that particular script- kind of like removing the first hundred peas that were mixed into a kettle of pea soup.

You have several choices-
find the conflicts and rewrite the libraries, or find a library that does everything you want, or write your own code.
Good points and I like the pea soup analogy!
Jan 24 '08 #6

P: 34
I found a simple solution avoid the conflicts with using both mootools and jquery
togethor. I just use the jquery no conflict option and in mootools...after some searching on the internet, just don't use '$' when calling a function.
Jan 24 '08 #7

acoder
Expert Mod 15k+
P: 16,027
I found a simple solution avoid the conflicts with using both mootools and jquery
togethor. I just use the jquery no conflict option and in mootools...after some searching on the internet, just don't use '$' when calling a function.
Thanks for posting your solution, but if you hit upon this problem again, you know which advice to follow.
Jan 25 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.