SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2005
    Location
    London, UK
    Posts
    422
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using rel=external instead of targe _new and _blank

    hi, i read that the target="_new" and blank are not web standard.

    there is a js solution.. in my head i have

    Code:
    <script type="text/javascript" src="external.js"></script>
    and on a link i use

    Code:
    <a href="" rel="external">
    this works in ff but not ie.. why.. i thought this was the best practice

    here is the js file.

    Code:
    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;

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,255
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)

    link target

    The target attribute is valid HTML. IMHO you should probably write HTML and NOT XHTML. But if you insist, Sitepoint has a good article about this that should be of help. http://www.sitepoint.com/article/sta...ompliant-world

  3. #3
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IE doesn't even support xhtml...

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But if you insist, Sitepoint has a good article about this
    Uhhmmm...did you notice his code is the same as the code in the article?
    this works in ff but not ie
    It works in IE6 for me.

  5. #5
    Ding Fries are Done! inter4design's Avatar
    Join Date
    Mar 2003
    Location
    usa
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    worked for me in IE6...even tried a different onload function.

    Code:
    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 = function() {
    externalLinks();
    }
    DoesItMatter
    - anyone seen my underwear?

  6. #6
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I always liked

    <a href="file.cfm" onclick="javascript:window.open(this.href);return false;" title="click me">Click here</a>

    It's XHTML valid, short n sweet, but DOES rely on the user having Javascript enabled.

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The latest thinking in web usability is that you should let your visitors choose for themselves when they want to open a link in a new tab or window. All browsers support this via options in the context menu.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Accessing onclick DOM info

    The rel="external" script is great and I have used it. Now I want to add an event to the link using the script - I have tried adding

    anchor.onmousedown = "return nav(this.href)";

    and it does not work.

    Any suggestions?
    How do I access all the DOM information on a page?

    Colin


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
  •