« Javascript » : différence entre les versions

m 1 révision importée
Aucun résumé des modifications
 
Ligne 1 : Ligne 1 :
<keywords content="Javascript"/>
<keywords content="Javascript"/>
== Charger dynamiquement un script ==
{{syntaxhighlight | lang=javascript | code=
//comment charger dynamiquement un script
function loadscript(url, callback)
{
    // adding the script element to the head as suggested before
  var head = document.getElementsByTagName('head')[0];
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = url;
  // then bind the event to the callback function
  // there are several events for cross browser compatibility
  script.onreadystatechange = callback;
  script.onload = callback;
  // fire the loading
  head.appendChild(script);
}
}}
== Liens Externes ==
== Liens Externes ==
{{grebox-jck|content=
{{grebox-jck|content=

Dernière version du 13 avril 2024 à 08:22

<keywords content="Javascript"/>

Charger dynamiquement un script

//comment charger dynamiquement un script

function loadscript(url, callback)
{
    // adding the script element to the head as suggested before
   var head = document.getElementsByTagName('head')[0];
   var script = document.createElement('script');
   script.type = 'text/javascript';
   script.src = url;

   // then bind the event to the callback function
   // there are several events for cross browser compatibility
   script.onreadystatechange = callback;
   script.onload = callback;

   // fire the loading
   head.appendChild(script);
}


Liens Externes