程序员人生 网站导航

JavaScript 参数数值 替换 replace

栏目:jscript时间:2014-03-16 22:39:31

JavaScript 参数数值 替换 replace

url:

http://www.taobao.com/go/act/shopping/sousuo55660.php?pid=mm_88888888_0_0&unid=123

js code:

<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{0,10}_d{0,10}_d{0,10}/i);
if(pid){
pid = pid[0].split("=")[1];
var unid= str.match(/unid=d{0,10}/i);
if(unid){pid += "%26"+unid[0]; }
var n = str.match(/n=d{0,5}/i);
if(n){pid += "%26"+n[0]; }

var reg=new RegExp("mm_0_0_0","gmi");
var as = document.getElementsByTagName("A");
for(var i = 0; i < as.length; i++){
as[i].href=as[i].href.replace(reg,pid);
}
document.body.innerHTML =document.body.innerHTML.replace(reg,pid)

}
isrun = true;
}
window.onload = init_pid;
setTimeout(init_pid,3000);
})();
</script>

来源:http://www.heiniuhaha.cn/blog/?p=1106

------分隔线----------------------------
------分隔线----------------------------

最新技术推荐