简体   繁体   中英

alert when script loaded

I can load external scripts with this code:

newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'http://code.jquery.com/jquery-latest.js';
document.getElementsByTagName('head')[0].appendChild(newScript);

But I looked this page: http://www.w3schools.com/jsref/event_onload.asp And I tried my new code:

<script type="text/javascript">
newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.onload = 'loaded();';
newScript.src = 'http://code.jquery.com/jquery-latest.js';
document.getElementsByTagName('head')[0].appendChild(newScript);

function loaded()
{
alert('The script is loaded');
}
</script>

But it dont worked. I want to get an alert when script is loaded

Change the line:

newScript.onload = 'loaded();';

To:

newScript.onload = loaded;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM