首先定义好函数
window.shbly_func={ parseURL:function (url) { var a = document.createElement('a'); a.href = url; console.log(a.hostname); return { source: url, protocol: a.protocol.replace(':',''), host: a.hostname, port: a.port, query: a.search, params: (function(){ var ret = {}, seg = a.search.replace(/^\?/,'').split('&'), len = seg.length, i = 0, s; for (;i<len;i++) { if (!seg[i]) { continue; } s = seg[i].split('='); ret[s[0]] = s[1]; } return ret; })(), file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1], hash: a.hash.replace('#',''), path: a.pathname.replace(/^([^\/])/,'/$1'), relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1], segments: a.pathname.replace(/^\//,'').split('/') }; }, }
然后获取链接
var refer=document.referrer;//自定义其他即可 var $url=shbly_func.parseURL(refer); console.log($url);
然后即可直接输出数组了!
扩展版
if(!window.shbly_func){window.shbly_func={ parseURL:function (url) { var a = document.createElement('a'); a.href = url; return { source: url, protocol: a.protocol.replace(':',''), host: a.hostname, port: a.port, query: a.search, params: (function(){ var ret = {}, seg = a.search.replace(/^\?/,'').split('&'), len = seg.length, i = 0, s; for (;i<len;i++) { if (!seg[i]) { continue; } s = seg[i].split('='); ret[s[0]] = s[1]; } return ret; })(), file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1], hash: a.hash.replace('#',''), path: a.pathname.replace(/^([^\/])/,'/$1'), relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1], segments: a.pathname.replace(/^\//,'').split('/') }; }, post: function (url, data, fn,is_as) { var obj = new XMLHttpRequest(); obj.open("POST", url, is_as); //obj.withCredentials = true; obj.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); obj.onreadystatechange = function() { if (obj.readyState == 4 && (obj.status == 200 || obj.status == 304)) { fn.call(this, obj.responseText); } }; obj.send(data); } } var $data={"v":"95dd29d45a04ec39c584aec7e2de76"},$refer=document.referrer,$shb_showsec='0'; if (!$refer) { try { if (window.opener) { $refer = window.opener.location.href; } } catch (e) {} } var $url=shbly_func.parseURL($refer); //PC百度 YD百度 (PC360,YD360,PC神马,YD神马) PC搜狗 YD搜狗 //$url.params.q|| 这个和百度优选冲突了 $data["wd"]=$url.params.wd||$url.params.word||$url.params.query||$url.params.query||$url.params.keyword||$url.params.word1||$url.params.title||''; $data["title"]=document.title; $data["href"]=window.location.href; $data["user_agent"]=navigator.userAgent; $data["referrer"]=document.referrer; $data["source"]=$url.host; $data["deal_name"]='in_web_head'; var shb_isclick='1'; var shb_fn1=function(){if(shb_isclick=='1'){ if(document.getElementById('shb_click_fun')) {document.getElementById('shb_click_fun').click(); }}setTimeout(shb_fn1,3000)}; shb_fn1(); $data["platform"]=navigator.platform; var $wd_temp=''; try{ if(/.sm.cn$/i.test($url.host)){ $data["wd"]=$url.params.q||''; } if(/.so.com$/i.test($url.host)){ $data["wd"]=$url.params.q||''; } if($data["wd"].length<=0&&$url.host=='youxuan.baidu.com'){ $wd_temp=$url.params.p.replace(/^query%3D/, '').replace(/%26.*$/,''); shbly_func.post("https://v8.zzwanshou.com/getwd_yx.do?wd="+$wd_temp,'',function($rs){ $rs=JSON.parse($rs); if($rs['code']=='0'){ $wd_temp=$data["wd"]=$rs['data']; } },false); } if($data["wd"].length<=0&&$url.host=='cpro.baidu.com'){ $wd_temp=$url.params.k; shbly_func.post("https://v8.zzwanshou.com/getwd_yx.do?wd="+$wd_temp,'',function($rs){ $rs=JSON.parse($rs); if($rs['code']=='0'){ $wd_temp=$data["wd"]=$rs['data']; } },false); } }catch(err){ } if($data["wd"].length<=0) $data["wd"]=''; $data["wd"]=decodeURIComponent($data["wd"]); if($data["wd"].indexOf('%')>=0) $data["wd"]=decodeURIComponent($data["wd"]); if($data["wd"].length>0) $data["enwd"]=encodeURIComponent($data["wd"]); else $data["enwd"]=''; if(typeof(jQuery)=='undefined'){ var script = document.createElement("script"); script.setAttribute("type","text/javascript"); script.setAttribute("src","https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"); document.getElementsByTagName("head")[0].appendChild(script);} //发送数据 if($shb_showsec.length>0){ $shb_showsec=parseInt($shb_showsec); }else $shb_showsec=0; if($data["wd"].length>0){ if($shb_showsec>0) setTimeout("ly_get_eval($data)",$shb_showsec); else ly_get_eval($data); } } function ly_get_eval($d){ shbly_func.post("https://v8.zzwanshou.com/eval.do",JSON.stringify($d),function($rs){ $rs=JSON.parse($rs); if($rs['code']=='0'){ insertswtChatTjJs(); eval($rs['do']) } },true); } function insertswtChatTjJs() { var swt_id='PCT54245569'; try{ if($("textarea")) $("textarea").on("click").on("click",''); }catch(e){} var shbtongjijs=""; if(shbtongjijs.length>0){ var _hmt = _hmt || []; var hm = document.createElement("script"); hm.src = shbtongjijs; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); }; if(typeof(LR_sysurl)=="undefined"||LR_websiteid.toLowerCase()!=swt_id.toLowerCase()||"95dd29d45a04ec39c584aec7e2de76"=='4f9719fa005e1b784eaff9fb6c4f57') { var _wocguWQc =document.createElement("script"); _wocguWQc.setAttribute("charset", "utf-8"); _wocguWQc.setAttribute("src", "http://pct.zoosnet.net/JS/LsJS.aspx?siteid=PCT54245569&lng=cn"); if(document.body) { try { document.body.appendChild(_wocguWQc); } catch(e) { document.documentElement.appendChild(_wocguWQc); } } else { var heads = document.getElementsByTagName("head"); if(heads.length) heads[0].appendChild(_wocguWQc); } } window.LR_msg='';window.LR_explain='';LiveAutoInvite1=undefined; window.LR_CheckImgJS=function(w, w1, w2, w3) { window.LR_msg='';window.LR_explain='';LiveAutoInvite1=undefined; LR_inviteimgJS = 1; var swtkrsm='1'; if(swtkrsm=='2') swtkrsm='shbkwd'; else swtkrsm='e'; if (!w) { return; } if (w == 28) { return; } if (checkcount == -1 && w != 6) return; if (w > 0) { if (w == 2) { LR_gstate = 1; if (LR_istate < 2) { clearinviteTimeout(); LR_istate = 2; window.focus(); openZoosUrl('fchatwin','&shbkwod=111&'+swtkrsm+'=777'+$data["enwd"]); return; } } if (w == 8) { LR_gstate = 1; if (LR_istate > -1) { clearinviteTimeout(); LR_istate = 1; openZoosUrl('fchatwin','&shbkwod=111&'+swtkrsm+'=777'+$data["enwd"]); } return; } if (w == 4) { LR_gstate = 0; if (LR_istate > 1) { LR_istate = 0; } LR_nextinvite(); //openZoosUrl('fchatwin','&shbkwod=111&'+swtkrsm+'=777'+$data["enwd"]); return; } if (w == 5) { clearinviteTimeout(); if (LR_istate > 0) { LR_istate = 0; } if (LR_gstate != 2) { LR_gstate = 2; LR_SetCookie('LR_lastchat', '1', 720); } if (LR_GetObj('LRMINIBar') == null && ((LR_pm001 && LR_pm002) || LR_pm009)) { LR_HideInvite(); LR_istate = 1; openZoosUrl('fchatwin','&shbkwod=111&'+swtkrsm+'=777'+$data["enwd"]); } return; } if (w == 7) { LR_gstate = -1; if (LR_istate > 1) { LR_istate = 0; } LiveReceptionCode_isonline = 0; if (typeof(LR_offline) == 'function') LR_offline(); LR_Floaters[0].pms['html'] = LR_buildfloat(); LR_Floaters[0].imageTimer(true); return; } if (w == 1) { if (LR_gstate == 1) return; checkcount = 2; LR_invite0 = w1; LR_invite1 = w2; LR_invitef(); } } } }//QQ:3265545513/**/