页面代码:
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 }
该文章转载于:http://blog.sina.com.cn/s/blog_bddd59750102x5sz.html
时间: 2024-08-11 05:45:34