Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
27
rated 0 times [  31] [ 4]  / answers: 1 / hits: 18970  / 15 Years ago, thu, september 3, 2009, 12:00:00

I would like to know how to load an external Javascript into my document from a function.


More From » function

 Answers
37

This is one way:



function loadDaFun() {
var script = document.createElement('script');
script.src = '/path/to/your/script.js';
var head = document.getElementsByTagName(head)[0];
head.appendChild(script);
}

[#98761] Tuesday, September 1, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brendan

Total Points: 426
Total Questions: 110
Total Answers: 94

Location: Western Sahara
Member since Mon, May 3, 2021
3 Years ago
brendan questions
;