跟踪用ajax的出站链接(JavaScript的) [英] Tracking outbound links using ajax (javascript)

查看:202
本文介绍了跟踪用ajax的出站链接(JavaScript的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于这个答案的问题在这里 http://stackoverflow.com/a/2078233/560972

I have a question regarding this answer here http://stackoverflow.com/a/2078233/560972

据我了解,使用JS(阿贾克斯)来跟踪传出的链接点击的最常见的问题是,前(快)的脚本可以获取数据,有时用户离开网页...?

As i understand, the most common problem using JS (Ajax) to track outgoing link clicks is that sometimes user leaves page before (faster) the script can grab the data...?

因此​​,也许有可能迫使某种延迟为了让脚本完成录制,然后让用户浏览到了另一个网站?延时当链接被点击和导航离开时

So maybe it is possible to force some sort of delay in order to let script finish recording and then let user navigate away to other site? Delay when link is clicked and navigation away occurs

这是否会帮助吗?我想〜200毫秒/ 300毫秒不会对用户可见,但它可能是不够的Ajax调用?

Will this help? I suppose ~200ms/300ms won't be visible for user but it could be enough for ajax call?

你觉得是什么?

谢谢!

推荐答案

使用jQuery:

$('a').click(function(e) {
   //check that it is offsite
   if($(this).attr("href").indexOf("http")==1) {
      //prevent the redirect;
      e.preventDefault();
      //do your tracking 
      $.ajax{
          url: 'yourtracking.php',
          data: "link=" + $(this).attr("href"),
          complete: function(){
              //now do the redirect
              window.location = $(this).attr("href");
          }

     }
  }
});

这篇关于跟踪用ajax的出站链接(JavaScript的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆