SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru Michel32's Avatar
    Join Date
    Nov 2004
    Posts
    641
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re-direct Open New Window

    Hi Guys,

    I need to redirect to my affiliate site using my own domain link. Now I send my visitors to my .html page which has the Redirect meta tag in it! The problem is that it doesn't accept target="_blank" within my link code.

    Any solutions here?


    Thanks!

  2. #2
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Not sure I fully get the question but ....

    Code JavaScript:
    function externalLinks() { 
      if (!document.getElementsByTagName) return; 
        var anchors = document.getElementsByTagName("a"); 
        for (var i=0; i<anchors.length; i++) { 
          var anchor = anchors[i]; 
          if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
            anchor.target = "_blank"; 
          } 
        }
    } 
    window.onload = externalLinks;

  3. #3
    SitePoint Guru Michel32's Avatar
    Join Date
    Nov 2004
    Posts
    641
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I add this code to my <body> tags and keep the meta redirect as well?
    Do I need to place URL inside the script somewhere?

  4. #4
    SitePoint Guru Michel32's Avatar
    Join Date
    Nov 2004
    Posts
    641
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="REFRESH" content="0;url=http://www.test.com/click?zone=0000&ad=000">
    <script type="text/javascript">

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-00000000-0']);
    _gaq.push(['_trackPageview']);

    (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();

    </script>
    </head>
    </html>


    This code will redirect, but doesn't open in a new window!

    I want page to open in a new window. How can I do this?


    Many thanks!

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The scenario is that a hyperlink on a page is clicked. This replaces the current page with the redirect page which opens the page to redirect to in a new window. Currently the user is then left with the redirect page.

    To avoid this you must go back one in the history using

    window.history(-1)

    at the end of the onload function.

  6. #6
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •