What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 1121 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > JavaScript > How to load another .js file in a .js file? ...
Poster

How to load another .js file in a .js file?

 Code Snippet posted by: Poster | Posted on: 3/1/2009 | Category: JavaScript Codes | Views: 4511 | Status: [Member] | Alert Moderator   


Lets say you have a .js file and you want another .js file to load from this .js file without addding another <script> tag to load .js file in every page of the website, you can use following function

function addJavascript(jsname) {

var th = document.getElementsByTagName('head')[0];
var s = document.createElement('script');
s.setAttribute('type','text/javascript');
s.setAttribute('src',jsname);
th.appendChild(s);
}


You can call above function like this
addJavascript('/yourjsfile.js');

Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 6:50:36 PM