但是騰訊的這個頁面改過版了,我是今天才發現的。用以前的代碼已經不能點擊開啟聊天視窗了,產生的新代碼比以前長了,多了個sigkey,64位的(好長 )。
以我的QQ為例子,在那個頁面產生的程式碼如下:
複製代碼 代碼如下:
<a href="http://sighttp.qq.com/cgi-bin/check?sigkey=cfad9f0a103b59616e94d667dd5755e92c2be98ded5ad949a940399e013adfe2"; target=_blank; onclick="var tempSrc='http://sighttp.qq.com/wpa.js?rantime='+Math.random()+'&sigkey=cfad9f0a103b59616e94d667dd5755e92c2be98ded5ad949a940399e013adfe2';var oldscript=document.getElementById('testJs');var newscript=document.createElement('script');newscript.setAttribute('type','text/javascript'); newscript.setAttribute('id', 'testJs');newscript.setAttribute('src',tempSrc);if(oldscript == null){document.body.appendChild(newscript);}else{oldscript.parentNode.replaceChild(newscript, oldscript);}return false;"><img border="0" SRC='http://wpa.qq.com/pa?p=1:56536321:2' alt="56536321"></a>
是不是很長?而且就這樣放進網頁,那麼頁面肯定過不了W3C認證,SRC是大寫,再如“;target=_blank; ”。如果要放好幾個QQ,那頁面豈不是也很亂。怎麼辦?
我對比了兩個QQ,發現只有那個64位的sigkey不一樣,所以可以把onclick移出來,代碼:
複製代碼 代碼如下:
<script type="text/javascript">
function QQtalk(sigkey) {
var tempSrc='http://sighttp.qq.com/wpa.js?rantime='+Math.random()+'&sigkey='+sigkey;
var oldscript=document.getElementById('testJs');
var newscript=document.createElement('script');
newscript.setAttribute('type','text/javascript');
newscript.setAttribute('id', 'testJs');
newscript.setAttribute('src',tempSrc);
if(oldscript == null) {
document.body.appendChild(newscript);
}
else {
oldscript.parentNode.replaceChild(newscript, oldscript);
}
return false;
}
</script>
然後直接onclick="return QQtalk('cfad9f0a103b59616e94d667dd5755e92c2be98ded5ad949a940399e013adfe2');"
網頁body內的代碼可以寫成: <a href="http://sighttp.qq.com/cgi-bin/check?sigkey=cfad9f0a103b59616e94d667dd5755e92c2be98ded5ad949a940399e013adfe2" target="_blank" onclick="return QQtalk('cfad9f0a103b59616e94d667dd5755e92c2be98ded5ad949a940399e013adfe2');"><img src="http://wpa.qq.com/pa?p=1:56536321:3" alt="56536321"></a>