Methods for judging Successful loading of JS files in IE and IE6 browsers
This article mainly introduces how to judge Successful loading of JS files in IE and IE6 browsers. This article uses vbscript to solve this problem. For more information, see
The file loading in the browser is actually very tangled with compatibility issues. I recently saw @ lifesinger make a specific summary. Which of the following is troublesome? IE6 ~ 8. If the load is successful or fails, a callback is used. On the Internet, I saw a solution: set a global variable or change the label attribute at the end of the file loading to identify whether the file is successful or not. But it is obviously not perfect. We need to modify and load the file.
Later, I tried another idea. I first created a vbscript and set src to a JS file. If the file is loaded normally, an error will be reported. Otherwise, no response will be made. In this case, if window. onerror is caught, the file is valid and then loaded normally. If not captured, a timeout is triggered in n seconds.
This part of code:
The Code is as follows:
If (ie & ie <9 ){
Vbs = doc. createElement (\ 'script \');
Vbs. language = \ 'vbscript \';
Vbs. src = file;
SaveErrorHandle = win. onerror;
Win. onerror = function (){
Load ();
Win. onerror = saveErrorHandle;
Return true;
};
SetTimeout (function (){
Ref. parentNode. insertBefore (vbs, ref );
}, 0 );
} Else {
Load ();
}