从https://stackoverflow.com/questions/11798336/change-all-website-links-to-affiliate-links-automatically?lq= 1 (第二个)获得了一个小脚本,用于将附属标签添加到 url
这就是我放在页面标题中的内容
<script type="text/javascript" src="http://。。。。。。/js/jquery-1.8.3.min.js"></script>
<script type='text/javascript'>
$("a").click(function() {
addAffiliate(this);
});
myCode = "http://moe.jlist.com/click/99999999?url=";
myAmazonCode = "&tag=99999999"
function addAffiliate(link) {
alert("enterting script: " + link.href);
if ((link.href).indexOf("jlist.com") > -1 && (link.href).indexOf(myCode) < 0) {
link.href = myCode + link.href;
}else if((link.href).indexOf("amazon.com") > -1 && (link.href).indexOf(myAmazonCode) < 0){
link.href = link.href + myAmazonCode;
}
alert(link.href);
return true;
}
</script>
但是,它不起作用,但是当我使用 jquery 将框架设置为“onload”时,它可以从上面链接提供的 url 在 jsfiddle.net 上运行
其次,我已经转换了另一个购物网站的代码,我想将其集成到我的代码中,这是他们给我的 wut 示例
function convert_aff_links( $_body, $_aff_id = '9999999' )
{
$_body = preg_replace
(
'@://(w+\.)?(playasia|play-asia)\.com/?([^/a-zA-Z])@',
'://www.play-asia.com/SOap-23-' . '83-' . $_aff_id . '-50-00.html$3',
$_body
);
$_body = preg_replace
(
'/paOS-(\d{2})/',
'SOap-23-' . '83-' . $_aff_id . '-50-$1',
$_body
);
return $_body;
}
提前致谢