Destramic Posted August 26, 2011 Share Posted August 26, 2011 hey guys im wondering who to import a js file insdie another js file...for instance if i wanted to load function function from the library into a js file to execute them...if someone has any good ways/ideas/tips please Quote Link to comment https://forums.phpfreaks.com/topic/245774-importing-js-inside-a-js-file/ Share on other sites More sharing options...
nogray Posted August 26, 2011 Share Posted August 26, 2011 You would create a new script html element with the source pointing to your javascript file. Append that file to the document head, eg. var scr = document.createElement('script'); scr.src = 'my_js_file.js'; document.getElementsByTagName('head')[0].appendChild(scr); Quote Link to comment https://forums.phpfreaks.com/topic/245774-importing-js-inside-a-js-file/#findComment-1262383 Share on other sites More sharing options...
Destramic Posted August 26, 2011 Author Share Posted August 26, 2011 would this be the correct way of doing it?...because i may way to add several scripts to that one javascript file...and that file will call the function and execute them there. Quote Link to comment https://forums.phpfreaks.com/topic/245774-importing-js-inside-a-js-file/#findComment-1262389 Share on other sites More sharing options...
nogray Posted August 26, 2011 Share Posted August 26, 2011 If the scripts are depending on each other, you would need to check the load status of each file (e.g. use the onstatuschange - complete or loaded - for IE and onload for other browsers). The only other way to load scripts using javascript is to request the file using ajax and eval the result text. Quote Link to comment https://forums.phpfreaks.com/topic/245774-importing-js-inside-a-js-file/#findComment-1262419 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.