The browser's file loading actually has very tangled compatibility issues. Recently I saw @lifesinger give a specific summary. What's more troublesome here is that IE6~8 does not distinguish between successful or failed loading, and they all go one callback. I saw a solution online, which is to place a global variable at the end of the loading file or change the attributes of the label to distinguish it, so that success or not is judged by this flag bit. But it is obviously not perfect, and the file needs to be loaded.
Later, I tried another idea, first create a vbscript, set src into a JS file. If the file loads normally, an error will definitely be reported, otherwise there will be no response. In this way, if window.onerror catches error, it means that the file is valid and it will be loaded normally. If not captured, a timeout will be triggered in n seconds.
This part of the code:
The code copy 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();
}