標籤:
頁面代碼:
js代碼:
1 function swt_hm(text){ 2 3 //請替換成"產生代碼 - 連結地址" 中的連結地址,不要去其他地方複製 4 5 ksChatLink = ‘http://kefu6.kuaishang.cn/bs/im.htm?cas=29935___399142&fi=32136&ism=1‘; 6 7 //var ksUserDefinedOpenNewChatWin=true; 8 9 //驗證參數是否存在 10 11 function checkQueryString(params,name){ 12 13 if(!params)return false; 14 15 return new RegExp("(^|&)"+ name +"=([^&]*)(&|$)", "i").test(params); 16 17 } 18 19 //擷取URL參數值 20 21 function getQueryString(url,name) { 22 23 var index = url.indexOf(‘?‘); 24 25 if(index==-1)return ‘‘; 26 27 url=url.substr(index+1,url.length); 28 29 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 30 31 var r = url.match(reg); 32 33 if (r != null) return (r[2]); 34 35 return ‘‘; 36 37 } 38 39 var openNewChatWin; 40 41 var localArr = ksChatLink.split("?"); 42 43 localArr.push(""); 44 45 if(typeof ksUserDefinedOpenNewChatWin!=‘undefined‘ && ksUserDefinedOpenNewChatWin==true){ 46 47 openNewChatWin = true; 48 49 }else if(checkQueryString(localArr[1],‘ism‘)){ 50 51 openNewChatWin = false; 52 53 }else{ 54 55 openNewChatWin = true; 56 57 } 58 59 //開啟快商通聊天視窗連結 60 61 function ksOpenLink(){ 62 63 var appendTailUrl=‘‘; 64 65 try{ 66 67 var cas = getQueryString(ksChatLink,‘cas‘); 68 69 if(cas){ 70 71 var vi=‘‘; 72 73 var dc = document.cookie.match(new RegExp(‘(^| )‘ + cas+‘_KS_‘+cas + ‘=([^;]*)(;|$)‘)); 74 75 if (dc != null){ 76 77 vi = (dc[2]); 78 79 } 80 81 if(vi){ 82 83 appendTailUrl += ‘&vi=‘+vi; 84 85 } 86 87 } 88 89 }catch(e){} 90 91 var ref=""; 92 93 try{if(opener.document.referrer.length>0){ref=opener.document.referrer;}}catch(e){ref=document.referrer;} 94 95 if(!ref || ref.length==0){ref=document.referrer;} 96 97 //對話網址 98 99 appendTailUrl += ‘&dp=‘+encodeURIComponent(window.location.href);100 101 //訪客來源102 103 if(ref)appendTailUrl+=‘&ref=‘+encodeURIComponent(ref);104 105 //對話標識106 107 if(text)appendTailUrl+=‘&sText=‘+encodeURIComponent(text);108 109 if(ksChatLink.indexOf(‘?‘)==-1){appendTailUrl=appendTailUrl.substring(1)+‘?‘;}110 111 ksChatLink+=appendTailUrl;112 113 //根據openNewChatWin設定開啟聊天視窗114 115 if(!openNewChatWin){116 117 window.location.href=ksChatLink;118 119 }else{120 121 var ksWin = window.open(ksChatLink,‘_blank‘);122 123 if(ksWin){124 125 try{ksWin.focus();}catch(e){} //將焦點定位到聊天視窗126 127 }128 129 }130 131 }132 133 //如果快商通代碼有載入完成,則使用快商通預設的開啟聊天視窗事件,否則使用自訂的開啟事件134 135 if(typeof KS!=‘undefined‘){136 137 var p = {};138 139 if(text)p[‘sText‘]=text;140 141 if(openNewChatWin)p[‘oTarget‘]=‘_blank‘;142 143 try{144 145 if(typeof KS.openChatWin==‘function‘){146 147 KS.openChatWin(p);148 149 }else if(typeof KS.openChatLink==‘function‘){150 151 KS.openChatLink(p);152 153 }else{154 155 ksOpenLink();156 157 }158 159 }catch(e){160 161 ksOpenLink();162 163 }164 165 }else{166 167 ksOpenLink();168 169 }170 171 }
View Code
該文章轉載於:http://blog.sina.com.cn/s/blog_bddd59750102x5sz.html
快商通代碼