got a small script from https://stackoverflow.com/questions/11798336/change-all-website-links-to-affiliate-links-automatically?lq=1 (the second one) to add affiliate tag into url
and this is what i put in the header of my page
<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>
however, it is not working, but it works on jsfiddle.net from the url provided by above link when i set the framework to ‘onload’ with jquery
secondly
i have convert codes from another shopping site that i want to integrate into my codes
this is a sample of wut they gave me
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;
}
thanks in advance
You are running this too early before the DOM has been loaded, thus there are no
atags in the page yet for it to attach to:Change it to this so it isn’t run until the document has loaded: