Copy codeThe Code is as follows:
/**
** Author: site120
** Function: get script part from html document
**/
Var loadJs = function (str, delayTime)
{
Var delayTime = delayTime | 100;
Var regExp_scriptTag = new RegExp ("<\ s * script ([^>] *)> ([\ s \ S] *?) </\ S * script \ s *> "," gi ");
Var regExp_scriptAttrib_src = new RegExp ("\ s * src? \ S * = \ s * (\ "([^ \"] +) \ "| \ '([^ \'] +) \ '| \ s * ([^ \ s] +) \ s *) "," gi ");
Var arr_scriptTag = null;
Var arr_scriptAttib = null;
Var scriptData = "";
Var jsList = new Array ();
While (arr_scripttag=regexp_scripttag.exe c (str ))! = Null)
{
While (arr_scriptattib1_regexp_scriptattrib_src.exe c (arr_scriptTag [1])! = Null)
{
If (arr_scriptAttib [3])
{
JsList. push (arr_scriptAttib [3]);
}
Else if (arr_scriptAttib [2])
{
JsList. push (arr_scriptAttib [2]);
}
Else
{
JsList. push (arr_scriptAttib [1]);
}
}
ScriptData + = (arr_scriptTag [2]);
}
For (var I = 0; I <jsList. length; I ++)
{
Var script = document. createElement ("script ");
Script. src = jsList [I];
Document. body. appendChild (script );
}
If (scriptData. length> 0)
{
Var fn = "_ siteFunction _" + new Date (). getTime () + "_" + parseInt (Math. random () * 10000) + "_ 120 ";
ScriptData = "var" + fn + "= function () {" + scriptData + "};" + fn + "();"
Window. eval (scriptData );
}
}
This is to use Js to process regular expressions. The principle is the same as that of Java,
The function is to read the source code of a webpage and extract and load all the script labels in it.
Here [\ s \ S] *? Use the non-Greedy mode to match all the code between the most recent script tags. Includes line feed