Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2007
    Location
    India
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Include js file inside js file

    Hi

    I have two .js files namely js1 and js.2. I want to include js1 file within js2 file. Is it possible. I tried with document.write("<script src="abc.js">.....</script>"). Let me have any solutions
    GemGuy

    Be friend of me
    Hey what a fun

  • #2
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Rather than 'including' js1 file within js2, you can use scripting within js2 to add js1 to the document.

    e.g.

    js2.js
    Code:
    var js1 = document.createElement('script');
    js1.type = 'text/javascript';
    js1.src = 'js1.js';
    
    var headEl = document.getElementsByTagName('head')[0];
    headEl.appendChild(js1);
    Last edited by Bill Posters; 07-13-2007 at 11:20 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •