#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    168
    Rep Power
    22

    Load js external file from javascript


    does anyone know how to load the js external file from javascript?

    i tried it on google to find the working one but none of them are working.

    please help!!!!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    74
    Rep Power
    19
    Why don't you load it from the html page?
  4. #3
  5. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,556
    Rep Power
    2338
    You mean, like

    Code:
    <script src="path/to/file.js"></script>
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    168
    Rep Power
    22
    I am writing the list of code in my javascript which is too large to write in html. I tried to read test1.js from key.js, but it won't letting me to read it.

    Here is the one i'm currently using it in my javascript:

    key.js

    Code:
    function loadjscssfile(filename, filetype)
    {
      var fileref=document.createElement('script');
      fileref.setAttribute("type","text/javascript");
      fileref.setAttribute("src", filename);
    }
    
    document.onkeydown = function(ev) 
    {	
       var key;
       ev = ev || event;
       key = ev.keyCode;
       var image1 = document.getElementById("image1").getElementsByTagName("img")[0];
    
       if(key == 13)
       {
          if (img1.indexOf('image1_yellow.jpg') != -1)
          {
             if (img5.indexOf('picture1_yellow.jpg') != -1)
             {
                loadjscssfile("test1.js", "js");
             }
          }
       }

    test1.js

    Code:
    var teststring="hello! you are reading another javascript file";
    alert("teststring);

    I can't read the test1.js from the key.js.

    any idea?
    Last edited by stephen100; March 23rd, 2013 at 11:31 PM.

IMN logo majestic logo threadwatch logo seochat tools logo