Second, use xmlhttprequestand window.exe cscript to dynamically execute a. js. The advantages of this method are obvious, but the efficiency may be reduced. If you are interested, you can test the speed yourself.
Code <Script language = "JavaScript">
Function bar (u ){
VaR x = Window. activexobject? New activexobject ("msxml2.xmlhttp"): New XMLHttpRequest ();
X. Open ("get", U, false );
X. Send (null );
S = x. responsetext;
Try again window.exe cscript (s)} catch (Ex) {window. eval (s)}; // the same function as the window.exe cscript method of iewould be provided in the lower-end windows. eval (s )};
}
Bar ("A. js ");
Foo ();
</SCRIPT> but this method still has shortcomings, that is, the code in A. js script has Chinese characters. How can this problem be solved? It will often be decoded, and decoding is exactly the weakness of JS. If vbs is used for decoding, then compatibility will become useless. To understand the specific application, I used the window.exe cscript method in the nevermodulesto parse the code for the JS package. This can be used with the JS namespace application.
Add script decoding (use vbs for decoding ):
<SCRIPT type = "text/JavaScript">
// <! [CDATA [
Function bar (u )...{
VaR x = Window. activexobject? New activexobject ("msxml2.xmlhttp"): New XMLHttpRequest ();
X. Open ("get", U, false );
X. Send (null );
S = parsescript (X. responsetext );
Try ..w.window.exe cscript (s)} catch (Ex)... {window. eval (s )};
}
Function parsescript (jscode )...{
// --- Tocurrentcharset (), decoded by aimingoo
Window.exe cscript (''+
'Function asc2unicode (n) '+
'Asc2unicode = CHR (n) '+
'End function' +
'Function safearray2str (body) '+
'Safearray2str = CSTR (body) '+
'End function', 'vbscript ');
VaR R1 =/% u (...) (..)/g, R2 =/% ([, A-F].) % (..)/g;
VaR tounicode = function ($0, $1, $2)... {return asc2unicode (parseint ($1 + $2, 16 ))}
Tocurrentcharset = function (body )...{
Return Unescape (escape (safearray2str (body). Replace (R1, "% $ 2% $1"). Replace (R2, tounicode ));
}; Jscode = tocurrentcharset (jscode );
Window.exe cscript (jscode, 'javascript '); // valid for IE, vbs Decoding
Return jscode;
}
Bar ('A. js ');
Foo ();
//]>