Some of you guys like add “Twitter button” or “Facebook Like button” on your website. But if your visitor from china that don’t use VPN or anyother jailbreak the G-F-W tools, it will slow down the page load until the browser’s default timeout time “60s”.
So i wrote this code snippet,now you can use this code snippet to test whether they could visit the Twitter or Facebook, if could then load the “Twitter button” or “Facebook Like button” scripts.
Enjoy it!
var Leeiio = {}; Leeiio.isFucked; Leeiio.fuck = function(){ var imgUrl = "http://twitter.com/favicon.ico?"; //You can change it to "http://www.facebook.com/favicon.ico?" imgUrl += new Date().getTime(); //add Time stamp to prevent the Browser's cache function removeElement(_element){ var _parentElement = _element.parentNode; if(_parentElement){ _parentElement.removeChild(_element); } } function testImg(isrc){ var fuckimg = document.createElement('iframe'); //I used to createElement('img') but it have some problem in webkit fuckimg.src = imgUrl; fuckimg.style.cssText = "display:none"; document.body.appendChild(fuckimg); fuckimg.timer = setTimeout(function(){ alert("Fuck it!(You know fuck what right?)"); fuckimg.src = null; fuckimg.onload = null; removeElement(fuckimg); Leeiio.isFucked = true; }, 3290); //set timeout to connect to twitter fuckimg.onload = function (){ clearTimeout(this.timer); alert("Nice!You are free man!"); fuckimg.src = null; fuckimg.onload = null; removeElement(fuckimg); Leeiio.isFucked = false; } } testImg(imgUrl); } Leeiio.fuck(); var timeTest = setTimeout(function(){ if(!Leeiio.isFucked){ //add your code here that you want to alert('Fuck!'); } clearTimeout(timeTest); },4000); |
See Demo here:http://leeiio.me/demo/fuck_yeah.html
看不懂…但是對於廣大P民來說…連測試也不用測試,肯定上不去。
昨晚剛訂閱完lz,Google reader就上不去了…哈哈
@ccaiai 就是判斷如果上不去就不載入那些Twitter或者Facebook的腳本了,免得影響頁面載入速度。
As a chiness, of course i know what to fuck (in your demo)
– -| 為什麼要用英文寫博客。。。
@Kevin Lynx 一般來說這篇文章只對看的懂的人才有用…大部分人是不會給自己的博客添加Twitter和Facebook按鈕的吧
作為一個經常在牆上行走的人來說,F還是不F已經沒那麼重要了。。。
@Kimcool 顯然你沒看懂這段代碼的用途…
這樣的確是很有必要,還有像一些外部的統計代碼如果資源載入不進來也悲催的勒~~~
@硬碟被格 google+1的按鈕代碼比較好會自動判斷終端載入的…
這個真的很有幫助!!Thx.
有 bug 啊,訪問頁面會自動彈出網頁顯示 twitter icon,這麼說你倒是成功繞過了 firefox 9.0.1 的彈窗攔截……
我的怎麼是正常的…要是twitter和facebook都能學習G+的載入代碼就好了,G+會自動中斷的
ff9(可能僅對linux)的bug,插入iframe變成新開窗口