Methods for judging Successful loading of JS files in IE and IE6 browsers

Source: Internet
Author: User

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 ();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.