Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8882459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:35:01+00:00 2026-06-14T20:35:01+00:00

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

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:35:02+00:00Added an answer on June 14, 2026 at 8:35 pm

    You are running this too early before the DOM has been loaded, thus there are no a tags in the page yet for it to attach to:

    <script type='text/javascript'>
    $("a").click(function() {
        addAffiliate(this);
    });
    </script>
    

    Change it to this so it isn’t run until the document has loaded:

    <script type='text/javascript'>
    $(document).ready(function() {
        $("a").click(function() {
            addAffiliate(this);
        });
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi all got a small problem accessing a looped php variable. My script loops
I got a small script which toggles my nav. But I'm using the nav
I've got a small action-script chart, that's meant to be live updating, and also
I've got a small cookie-leaving aspx script. I'm wondering if it's faster to just
Got a complex SELECT query, from which I would like to insert all rows
I have a small rails app I got all gung-ho on tonight wanting to
I've got a small script that detects if the user is using a certain
I've got a small little page that is going to be viewed from a
I've got a small script which is returning a string/path. This path is an
So I got this small script - if (isset($_POST['submit']) && $_POST['description'] == '') {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.