Categories
JavaScript

Javascript: Attach a js file to a page dynamically

The steps:
// Create a script kind of tag:
to_attach = document.createElement(”script”);
// Define the source of your file, and the type of the attachment
to_attach.src=”http://wwww.test.com/your_script.js” mce_src=”http://wwww.test.com/your_script.js” ;
to_attach.type=”text/javascript”;
// Append it to the body:
document.getElementsByTagName(”body”)[0].appendChild(to_attach)

Leave a Reply

Your email address will not be published. Required fields are marked *