简体   繁体   English

您如何使用javascript / jQuery重写亚马逊会员链接?

[英]How do you use javascript/jQuery to rewrite amazon affiliate links?

Basically what I want the script to do, is add my affiliate ID to all Amazon links posted by my users.(Kinda what SO is doing, minus the whole redirect/racking thing) 基本上,我希望脚本执行的操作是将我的会员ID添加到我的用户发布的所有Amazon链接中。(Kinda所做的就是,减去整个重定向/竞争)

Here is the code I'm using, and for some reason it's not working. 这是我正在使用的代码,由于某种原因,它无法正常工作。

   <script type="text/javascript">
$(document).ready(function() {


    $('a[href*='amazon.com']').each(function() { this.href = this.href.replace(/\?.*$/,"") + $.query.load(this.href).set("tag","affID").toString();});
});
</script>

我对jQuery不熟悉,但我认为此脚本可能会有所帮助: http : //petewilliams.info/blog/2009/07/javascript-amazon-associate-link-localiser/

I think it might have something to do with your quotes. 我认为这可能与您的报价有关。 Try it like this: 像这样尝试:

 $('a[href*="amazon.com"]').each(function() ... etc

Notice the difference? 注意区别吗? The point is that if you use single quotes on the outside, you need to use double quotes on this inside. 关键是,如果在外部使用单引号,则需要在内部使用双引号。 Or vice versa. 或相反亦然。

Did you add the jquery plugin it requires. 是否添加了所需的jquery插件。

$.query.load(this.href)

this requires the jquery query plugin I suppose. 这需要我假设的jquery查询插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM