SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member lisamariexo's Avatar
    Join Date
    Aug 2012
    Location
    England
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Replacement for target=' blank' isn't working

    So, since W3C has 'dropped' the target='_blank' attribute, I decided to look up another solution to ensure that my link would open up into a new window.
    However, when i entered the code given in here: http://www.ajaxblender.com/open-link...get-blank.html
    in my header, when clicking on the link my page just opens in the same window. I have tried both options!
    Then, someone suggested that i use this

    'function externalLinks(){if(!document.getElementsByTagName){return;}var anchors=document.getElementsByTagName("a");for(var i=0;i<anchors.length;i++){var anchor=anchors;if(anchor.getAttribute("href")&&(anchor.getAttribute("rel")=="external"||anchor.getAttribute("rel")=="external nofollow"||anchor.getAttribute("rel")=="nofollow external")){anchor.target="_blank";}}}
    externalLinks();

    this is what you would use for the links...

    <a href="blah" rel="external">
    or <a href="blah" rel="nofollow external">
    or <a href="blah" rel="external nofollow">

    any of those will open in a new window'


    which resulted in having code showing as text in the header and didn't even work anyway!
    help?!!

    this is the site for reference, i'm referring to the home page code http://www.ln-backups.co.uk/partsexport/

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,807
    Mentioned
    141 Post(s)
    Tagged
    0 Thread(s)
    Quite a simple fix, you need to place the code in <script> tags like so:
    Code:
    <script type="text/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.getAttribute("rel")=="external nofollow"||anchor.getAttribute("rel")=="nofollow external")){anchor.target="_blank";}}}
    externalLinks();
    </script>
    Let me know if that still doesn't solve the problem for you.

  3. #3
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It appears the W3c has removed the deprecated status for this attribute. I had to check, as it seemed a bit daft removing something that people would still use by doing it a different way.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if


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
  •