Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How to insert script into HTML head dynamically using Javascript ?

share|improve this question
    
What server side language do you use? –  Meligy Feb 27 '11 at 9:51
    
no server side language i want to use. –  Wasim Feb 27 '11 at 9:55
    
using javascript at button click i want to insert into head. –  Wasim Feb 27 '11 at 9:56
    
Check this solution: unixpapa.com/js/dyna.html –  eolith Feb 27 '11 at 9:57

1 Answer 1

var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.onreadystatechange = function() {
    // if (this.readyState == 'complete') { callFunctionFromScript(); }
}
script.src = 'path/to/your-script.js';
head.appendChild(script);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.