关于Arctic’s Internal Alexa Redirect ,这个是不错的点子,将自己站点的链接重定向到http://redirect.alexa.com/redirect?http://cbmland.com/ ,然后等待http://redirect.alexa.com转回自己的站点链接。这样可以完成一次流量统计。(统计效果有待观察)
具体说明见http://hellobmw.com/archives/version-11-of-arctics-internal-alexa-redirect.html

看上去不错,我尝试着安装了这个插件。

研究了一下代码,发现在本站的链接A标签上都加了一句onclick=”parent.location.href=’http://redirect.alexa.com/redirect?http://cbmland.com/’;event.returnValue=false”,由这里来实现重定向到alexa.com。

 现在的代码是
<a href=”http://cbmland.com/” onclick=”parent.location.href=’http://redirect.alexa.com/redirect?http://cbmland.com/’;return event.returnValue=false”>cbm’s land</a>

接着发现了几个问题:
1.使用的是parent.location来定向到alexa.com,等于window.location定向页面,这种跳转没有带上referer信息。
2.在这里return event.returnValue=false不知道有没有必要。这里指定的是onclick事件的返回,但重定向的是parent.location,无论onclick返回是否为false,parent.location都已经开始执行了,我想这样是禁止不了parent.location转向的。
3.加大页面文件量。每个A标签上加上了很多垃圾代码,如果onclick内容封装到一个公共函数不是更好呢?

改进方法,写个公用函数:
<script language=”javascript” >
function onclick_func(event){
event.href=’http://redirect.alexa.com/redirect?’+event.href;
}
</script>

每个A标签变为<a onclick=”onclick_func(this)” href=”http://cbmland.com”>cbm’s land</a>

这样每个连接加上的数据就只有onclick=”onclick_func(this)”,相对之前那么长的onclick事件是不是短了很多,在页面链接比较多的情况下可以节省不少页面的字节数。

你还可以将函数命名更短,那样节省下载流量是可想而知的。

再简化代码:

<a href=”http://cbmland.com/” onclick=”e(this)”>cbm’s land</a> 

<script language=”javascript”>function e(e){e.href=”http://redirect.alexa.com/redirect?”+e.href;}</script>
优化了的插件下载:arctic_alexaredirect_1.2.zip (基于1.1版本优化)