Copy Code code 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.exec (str))!= null)
{
while ((Arr_scriptattib=regexp_scriptattrib_src.exec (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 the use of JS to deal with regular expressions, the principle of the same as Java,
The function is to read a section of the source code, and put all the script tags inside it, intercept and load the run.
What's in this [\s\s]*? Use non-greedy mode to match all the code between the most recent script tags. Include line wrapping