I have to do the cross-domain ajax,so I try the jsonp.
Then I will have to add the script
element dynamiclly to the page,however I can not check its sta
Looking at yepnope.js it uses both onload
and onreadystatechange
but it also uses a timeout loop to check the readystate
property of the script element, see here.
The load
event for script elements was introduced in HTML5, prior to that it was only available for frameset and body elements (though most browsers also implemented it for img elements too). So if you want to support earlier browsers you'll need to be creative.
One solution is to put a function call at the top of the script to say that the script has been loaded, as the browser should not execute any code in the script until it's loaded in its entirety.
Another is to insert a second script with the "I'm loaded" function or flag immediately after the first in the presumption that the second will not be executed until the first has been loaded and executed.
For IE, think of alternate ways to check load has happened, e.g. in your script file add the line
script_myScriptUniqueName_loaded = true;
and then in the dynamic add, if script.onload
is not null
(before setting a callback) use window.setInterval
to check for existance of script_myScriptUniqueName_loaded
, with a timeout to throw error, and if exists call callback.
Remember to do window.clearInterval
when you're done.