1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

JS Redirect For Aff Link - Need help

Discussion in 'HTML & JavaScript' started by pallyD, Jul 31, 2012.

  1. pallyD

    pallyD Junior Member

    Joined:
    Aug 6, 2010
    Messages:
    137
    Likes Received:
    95
    Location:
    MW
    Code:
    [COLOR=#FFFFCC]<a id="link" href="http://google.com" onclick="go();">Google</a> \\Put your regular .com link in this part[/COLOR]
    
    
    [COLOR=#FFFFCC]<script type="text/javascript">[/COLOR]
    
    
    [COLOR=#FFFFCC]function go() {[/COLOR]
    
    
    [COLOR=#FFFFCC]document.getElementById('link').href = 'http://google.com/pda'; \\then put the aff link here[/COLOR]
    
    
    [COLOR=#FFFFCC]}[/COLOR]
    
    
    [COLOR=#FFFFCC]</script>[/COLOR]
    This would give me a link to click and redirect to cloaked link, but I need it so it redirects immediately, i.e. no clicking just right as the user loads the page like a 301.
     
  2. jonbenwaa

    jonbenwaa Newbie

    Joined:
    Jul 6, 2012
    Messages:
    12
    Likes Received:
    5
    Occupation:
    web dev
    HTML:
    <script type="text/javascript">
    window.location.href="somelink";
    </script>
    
    put this code before the title tag. I didn't test it out, but pretty sure it should work. Then again I've been up for about 20 hours right now...
     
  3. RightInTwo

    RightInTwo Power Member

    Joined:
    Feb 23, 2010
    Messages:
    744
    Likes Received:
    381
    Home Page:
    is there a reason you are using javascript as opposed to PHP? Here is what I do for my affiliate links:

    1). Create a new folder on your hosting called "go" or "out".
    2). In the folder, create a new page called index.php
    3). paste this code in the index.php page:

    Code:
    <?php
    
       header( 'Location: http://www.affiliatesite.com/affiliatelinkID' ) ;
    
    
    ?>
    
    
    4. When you create the page on your site, your new link will be http://www.yoursite.com/go
     
  4. jonbenwaa

    jonbenwaa Newbie

    Joined:
    Jul 6, 2012
    Messages:
    12
    Likes Received:
    5
    Occupation:
    web dev
    Agree with above as a server side answer would be best, as js can always be altered by the client.
     
  5. izkech

    izkech Regular Member

    Joined:
    Jun 7, 2012
    Messages:
    433
    Likes Received:
    116
    Sorry to hijack this thread and forgive my noobs question,can you guys say why do we need to use this redirect script??
     
  6. pallyD

    pallyD Junior Member

    Joined:
    Aug 6, 2010
    Messages:
    137
    Likes Received:
    95
    Location:
    MW
    You by no means NEED to use it, but cloaking your link from a potential buyer may prevent them from taking your commission when they buy.

    @RightInTwo That will prevent them from seeing it when clicking, but e.g. ClickBank has the ?hop=pallyD at the end of the URL, but when you use php redirect the hop will still show. I managed to go to the google homepage with script I used, but it showed up in the browser URL box as google.com/pda, so I assume I can have it not show a "?hop=pallyD" while still giving me the commission.
    Is this true at all?

    For the meantime I just have the PHP redirect going until I can get this to work.
     
    • Thanks Thanks x 1
  7. RightInTwo

    RightInTwo Power Member

    Joined:
    Feb 23, 2010
    Messages:
    744
    Likes Received:
    381
    Home Page:
    You can use a double meta refresh to cloak the link and also hide the referrer.
     
  8. pallyD

    pallyD Junior Member

    Joined:
    Aug 6, 2010
    Messages:
    137
    Likes Received:
    95
    Location:
    MW
    That's genius mate, and it seems to work with ClickBank. Thanks very much.
     
  9. RightInTwo

    RightInTwo Power Member

    Joined:
    Feb 23, 2010
    Messages:
    744
    Likes Received:
    381
    Home Page:
    Happy to help. In fact, I think somewhere on my computer I have a script if you want it. PM me if you do and I can try and find it.