Replace RegExp replace with a regular expression
<! DOCTYPE html>
<Html>
<Body>
<A href = "http://www.taobao.com/index_global.php? Pid = mm_0_0_0 "> 0000 </a>
<A href = "http://www.taobao.com/index_global.php? Pid = mm_123_0_0 "> 111 </a>
<A href = "http://www.taobao.com/index_global.php? Pid = mm_123_0_0 "> 2222 </a>
<A href = "http://www.taobao.com/index_global.php? Pid = mm_888_999_0000 "> 33333 </a>
<Script type = "text/javascript">
(Function (){
Var isrun = false;
Var init_pid = function (){
If (isrun) return;
Var str = window. location. search;
Var pid = str. match (/pid = mm _ \ d {}/I );
If (pid ){
Pid = pid [0]. split ("=") [1];
Var unid = str. match (/unid = \ d {0, 10}/I );
If (unid) {pid + = "&" + unid [0];}
Var n = str. match (/n = \ d {0, 5}/I );
If (n) {pid + = "&" + n [0];}
// Var reg = new RegExp ("mm_0_0_0", "gmi ");
Var reg = new RegExp (/mm _ \ d {}/ig );
Var as = document. getElementsByTagName ("");
For (var I = 0; I <as. length; I ++ ){
As [I]. href = as [I]. href. replace (reg, pid );
}
}
Isrun = true;
}
SetTimeout (init_pid, 3000 );
})();
</Script>
</Body>
</Html>
Source: http://www.heiniuhaha.cn