使用jQuery,我如何拦截超链接点击事件临时? [英] With jQuery, How Do I Intercept Hyperlink Click Events Temporarily?

查看:180
本文介绍了使用jQuery,我如何拦截超链接点击事件临时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题涉及联属网络营销,但实际上是一个关于在超链接去往另一个网站之前拦截超链接的常见问题,您可以在这里将访问者活动记录到数据库。

This question refers to affiliate marketing, but really is a generic question about intercepting hyperlinks before they go off to another site, where you can log visitor activity to a database.

我的联盟营销客户有一个很好的问题。想象一下,一个场景,你有产品从亚马逊通过其API,给一个种子关键字。现在假设访问者点击其中一个产品,在亚马逊上查看。该产品的网址可能如下所示(这只是一个演示):

My affiliate marketing client had a really good question. Imagine a scenario where you have products pulled back from Amazon over its API, given a seed keyword. Now imagine a visitor clicks one of those products to view it on Amazon. The URL for that product might look like this (and this is just a demo):

http://www.amazon.com/dp/B0042RU3Y0/?tag=xxxxxxxxxxxxxxxx-20

但猜测?它不传递seed关键字。因此,我们不知道哪些种子关键字是最有效的。相反,她希望我们可以通过以下,然后跟踪这种方式:

But guess what's wrong with that? It's not passing that seed keyword. So, we have no idea which seed keywords were the most effective. Instead, she was wishing we could pass the following and then track that somehow:

http://www.amazon.com/dp/B0042RU3Y0/?tag=xxxxxxxxxxxxxxxx-20&seed=laptops

我没有看到亚马逊上的任何文档,我们可以传递额外的参数,然后通过过滤器在报告中跟踪它们。

I didn't see any docs on Amazon where we could pass extra params and then track them in the reports by a filter.

所以,我唯一能想到的是,我们需要捕获点击之前,它去了亚马逊。换句话说,在该事件冒泡并执行之前,不知何故在jQuery中我可以先拦截它,解析该超链接的href URL,粘贴这个额外的种子关键字信息,通过AJAX发送回PHP页面和数据库表,然后释放该单击事件,以便它被执行,浏览器转到亚马逊。

So, the only thing I could think of is that we need to capture the click before it goes off to Amazon. In other words, before that event bubbles up and is executed, somehow in jQuery I can intercept it first, parse the href URL for that hyperlink, tack on this extra seed keyword information, send it over AJAX back to a PHP page and a database table, and then release that click event so that it is executed and the browser goes off to Amazon.

有人知道在jQuery中如何做到这一点吗?我知道AJAX部分 - 只是没有捕获点击的点击拦截部分,然后释放它。

Does anyone know how this is done in jQuery? I know the AJAX part -- just not the click intercept part that grabs the click, then releases it.

推荐答案

var seed = "&seed=laptops";
$("a").live('click',function(){
    $(this).attr('href', $(this).attr('href')+seed);
});

这篇关于使用jQuery,我如何拦截超链接点击事件临时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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