Created
June 5, 2013 14:46
-
-
Save ElfhirDev/5714384 to your computer and use it in GitHub Desktop.
Include a js script in a js script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function include(src, attributes) | |
{ | |
try { | |
attributes = attributes || {}; | |
attributes.type = "text/javascript"; | |
attributes.src = src; | |
var script = document.createElement("script"); | |
for(aName in attributes) | |
script[aName] = attributes[aName]; | |
document.getElementsByTagName("head")[0].appendChild(script); | |
return true; | |
} catch(e) { return false; } | |
} | |
// Load the file ; be careful of the path | |
function test() { | |
include('monfichier.js'); | |
} | |
// then you can call object and var in 'monfichier.js' | |
///////////////////////////////////////////// | |
// Exemple 1 | |
// | |
// var file = "monfichier.js"; | |
// include(file); | |
// | |
// Exemple 2 | |
// var file = "http://www.example.com/script.js"; | |
// var attributes = {charset:"utf-8"}; | |
// | |
// include(file, attributes); | |
// | |
// Return true if it can load the file. | |
////////////////////////////////////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment