I want to execute a fairly large javascript file using onload function. I have made it as external but don't know how to use it with onload function. Any help will be highly appreciated.
first attach that js file inside head tag of your page using: <script type="text/javascript" language="javascript" src="file.js"></script> then call it in body tag like this: <body onLoad="function()"> hope it works
Are you asking for import a javascript from other javascript (inside or outside your html) ? If yes, you can use: document.write("<script type='text/javascript' src='test.js'></scr"+"ipt>"); Code (markup): Note that you should split the closing script tag into two parts. Another option is using the DOM model: // Create the Script Object var script = document.createElement('script'); script.src = 'server.js'; script.type = 'text/javascript'; script.defer = true; script.id = 'scriptID'; // This will help us in referencing the object later for removal // Insert the created object to the html head element var head = document.getElementsByTagName('head').item(0); head.appendChild(script); Code (markup): And to remove that object: var head = document.getElementsByTagName('head').item(0); var old = document.getElementById('scriptID'); if (old) head.removeChild(old); Code (markup):