Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. onclick load js file

onclick load js file

Scheduled Pinned Locked Moved Web Development
javascripthelphtmltools
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    militiaware
    wrote on last edited by
    #1

    why this is wont work on ie6 1...var html_doc = document.getElementsByTagName('head').item(0); 2...var js = document.createElement('script'); 3...js.setAttribute('language', 'javascript'); 4...js.setAttribute('type', 'text/javascript'); 5...js.setAttribute('src', script_filename); 6...html_doc.appendChild(js); 7...return false; there's no error... and the strange thing is when i add a nalert statement after line 6, it works fine... i need help! :~

    Faris Madi Nothing Comes Easy (N.C.E.)

    B B A 3 Replies Last reply
    0
    • M militiaware

      why this is wont work on ie6 1...var html_doc = document.getElementsByTagName('head').item(0); 2...var js = document.createElement('script'); 3...js.setAttribute('language', 'javascript'); 4...js.setAttribute('type', 'text/javascript'); 5...js.setAttribute('src', script_filename); 6...html_doc.appendChild(js); 7...return false; there's no error... and the strange thing is when i add a nalert statement after line 6, it works fine... i need help! :~

      Faris Madi Nothing Comes Easy (N.C.E.)

      B Offline
      B Offline
      Bradml
      wrote on last edited by
      #2

      maybe the script does not run by default. try calling a function.


      Brad Australian - Christian Graus on "Best books for VBscript" A big thick one, so you can whack yourself on the head with it.

      1 Reply Last reply
      0
      • M militiaware

        why this is wont work on ie6 1...var html_doc = document.getElementsByTagName('head').item(0); 2...var js = document.createElement('script'); 3...js.setAttribute('language', 'javascript'); 4...js.setAttribute('type', 'text/javascript'); 5...js.setAttribute('src', script_filename); 6...html_doc.appendChild(js); 7...return false; there's no error... and the strange thing is when i add a nalert statement after line 6, it works fine... i need help! :~

        Faris Madi Nothing Comes Easy (N.C.E.)

        B Offline
        B Offline
        badgrs
        wrote on last edited by
        #3

        In what way doesn't it work? If an alert at line 6 gets fired then the script element has obviously been added to the DOM succesfully. As above ^^ you probably have to invoke the script some how.

        M 1 Reply Last reply
        0
        • B badgrs

          In what way doesn't it work? If an alert at line 6 gets fired then the script element has obviously been added to the DOM succesfully. As above ^^ you probably have to invoke the script some how.

          M Offline
          M Offline
          militiaware
          wrote on last edited by
          #4

          Sorry for not being clear! actually the code is like this function load(script_filename) { var html_doc = document.getElementsByTagName('head').item(0); var js = document.createElement('script'); js.setAttribute('language', 'javascript'); js.setAttribute('type', 'text/javascript'); js.setAttribute('src', script_filename); html_doc.appendChild(js); return false; } and: now, on click the extrnal js file loaded and running fine on firefox, ie7, opera, but not on ie6 in ie6 the js file seems to be trying to load.... when i add the alert after the appendChild statement, the problem disappear and the external js loads. Faris Madi Nothing Comes Easy (N.C.E.)

          B 1 Reply Last reply
          0
          • M militiaware

            Sorry for not being clear! actually the code is like this function load(script_filename) { var html_doc = document.getElementsByTagName('head').item(0); var js = document.createElement('script'); js.setAttribute('language', 'javascript'); js.setAttribute('type', 'text/javascript'); js.setAttribute('src', script_filename); html_doc.appendChild(js); return false; } and: now, on click the extrnal js file loaded and running fine on firefox, ie7, opera, but not on ie6 in ie6 the js file seems to be trying to load.... when i add the alert after the appendChild statement, the problem disappear and the external js loads. Faris Madi Nothing Comes Easy (N.C.E.)

            B Offline
            B Offline
            Bradml
            wrote on last edited by
            #5

            I'm not a javascript guru, but try these 2 things: try call a function that is in the script you loaded remove the rturn statment.


            Brad Australian - Christian Graus on "Best books for VBscript" A big thick one, so you can whack yourself on the head with it.

            1 Reply Last reply
            0
            • M militiaware

              why this is wont work on ie6 1...var html_doc = document.getElementsByTagName('head').item(0); 2...var js = document.createElement('script'); 3...js.setAttribute('language', 'javascript'); 4...js.setAttribute('type', 'text/javascript'); 5...js.setAttribute('src', script_filename); 6...html_doc.appendChild(js); 7...return false; there's no error... and the strange thing is when i add a nalert statement after line 6, it works fine... i need help! :~

              Faris Madi Nothing Comes Easy (N.C.E.)

              A Offline
              A Offline
              Alexandru Lungu
              wrote on last edited by
              #6

              It works; but it depends on what exactly you do next; if you try to access something from that file it wont work because it isn't loaded yet (it loads asynchronously, in a separate thread) You can understand more by reading this articles that details and solves these problems: Challenge-Me: Javascript Including Engine - Part I Challenge-Me: Javascript Including Engine - Part II Challenge-Me: Javascript Including Engine - Part III You can also visit the IncludingEngine site Allex

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups