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变成新开窗口