Inclus dynamiquement un fichier javascript.
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; }
}
bool include ( string src [, object attributes ] )
Retourne TRUE si le fichier a pu être inclus, ou FALSE si une erreur survient.
Exemple #1 Exemple avec include()
var file = "monfichier.js"; include(file);
Exemple #2 Exemple avec include()
var file = "http://www.example.com/script.js";
var attributes = {charset:"utf-8"};
include(file, attributes);
Commentaire(s)
Poster un commentaire