Import JavaScript in JavaScript File
-
Hi everybody, I need to call/include/import a JavaScript file (*.js) in another JavaScript (*.js) file. How can i do this. I tried to do writing a line in script file like: document.write(""); But this method writes the line to the document so i cannot use/call functions from another files which are stored in different folders. Thanks for your help.
-
Hi everybody, I need to call/include/import a JavaScript file (*.js) in another JavaScript (*.js) file. How can i do this. I tried to do writing a line in script file like: document.write(""); But this method writes the line to the document so i cannot use/call functions from another files which are stored in different folders. Thanks for your help.
-
Hi everybody, I need to call/include/import a JavaScript file (*.js) in another JavaScript (*.js) file. How can i do this. I tried to do writing a line in script file like: document.write(""); But this method writes the line to the document so i cannot use/call functions from another files which are stored in different folders. Thanks for your help.
You're on the right track - but instead of writing to the document, create the
<script>
element usingdocument.createElement()
, set the attributes programatically, and then attach it to the document. If you want an example... or a robust, ready-to-use implementation... check out the jQuery getScript function[^].Citizen 20.1.01
'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'
-
You're on the right track - but instead of writing to the document, create the
<script>
element usingdocument.createElement()
, set the attributes programatically, and then attach it to the document. If you want an example... or a robust, ready-to-use implementation... check out the jQuery getScript function[^].Citizen 20.1.01
'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'
Try this:
-
Try this: