file1: <script> function include(destination) { var e=window.document.createElement('script'); e.setAttribute('src',destination); window.document.body.appendChild(e); } </script><body onLoad="include('some-other-file.html');"> Code (markup): some-other-file.html: alert('hi'); you should see a box
i'm not sure if that is what I am looking for. i want to include a javascript file inside another one.
Um, there's no include() function in Javascript. discoverclips is correct. Also, remember to always use the type attribute on script elements ("text/javascript"). Regards - P
It was my mistake, I didn't realize that include isn't the Javascript function. Actually what we are doing is that we are using a customized function described below: function include(filename) { var head = document.getElementsByTagName('head')[0]; script = document.createElement('script'); script.src = filename; script.type = 'text/javascript'; head.appendChild(script) } Code (markup): This function is defined in a file jsHandler.js and we include this file in all our pages at the top. once this file is included you can use include("abc.js"); any where you want. Thanks for notifying and I apologize for not providing complete information. Let me know if you guys have any problem in using it.
This might interest you (copy and paste URL to your browser): mashhoor.ws/2006/07/19/javascript-includes/ It's not bullet-proof, sometimes it doesn't work for some reason, but it's worth a try.