<SCRIPT> in HTML / Multiple js frameworks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gsherp
    New Member
    • May 2007
    • 34

    <SCRIPT> in HTML / Multiple js frameworks

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

    Code:
    <span id="changeit"><script src="test1.js"></script></span>
    
    <input type="button" onClick="document.getElementById('changeit").innerHTML="<script src="test2.js"></script>" />
    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.
    Last edited by gsherp; Jan 23 '08, 08:13 AM. Reason: additional info.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Give the script tag an id and change its src:
    [code=javascript]document.getEle mentById("scrip tID").src="news rc.js";[/code]

    Comment

    • gsherp
      New Member
      • May 2007
      • 34

      #3
      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?

      Comment

      • mrhoo
        Contributor
        • Jun 2006
        • 428

        #4
        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.

        Comment

        • amphibian1
          New Member
          • Dec 2007
          • 7

          #5
          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.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by mrhoo
            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!

            Comment

            • gsherp
              New Member
              • May 2007
              • 34

              #7
              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...afte r some searching on the internet, just don't use '$' when calling a function.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Originally posted by gsherp
                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...afte r 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.

                Comment

                Working...