Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: target="new"

  1. #1
    New Coder
    Join Date
    Sep 2005
    Location
    Latina (Italy)
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question target="new"

    I hope this is not a problem that many people before me can have asked about but...
    if I do not use javascript, is there an XHTML-compliant way to make an anchor open another window? As well known, the attribute target="new" ir target="blank" is not accepted anymore by W3C standards!

  • #2
    New Coder
    Join Date
    Jun 2005
    Location
    Ottawa, Ontario
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You are allowed to use target="_blank", but only if you are using a Transitional or Frameset DTD. The Strict DTD will produce a validation error.
    Mike Badgley,
    A+ Web Creations

  • #3
    New Coder
    Join Date
    Sep 2005
    Location
    Latina (Italy)
    Posts
    73
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you!
    I'll read more about this...

    Considering my first theme, that is accessibility, do you think I'd better abandon the Strict DTD compliance or keep it and use js?

  • #4
    Senior Coder gsnedders's Avatar
    Join Date
    Jan 2004
    Posts
    2,340
    Thanks
    1
    Thanked 7 Times in 7 Posts
    I'd just keep it opening in the same window, let the user choose if they want it in a new window/tab.

  • #5
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by Error 404
    I'd just keep it opening in the same window, let the user choose if they want it in a new window/tab.
    It's not always the case that the user knows the browser well enough to know how to open links in a new window.

    Fwiw, there's some worthwhile reading over at this AccessifyForum thread.
    http://www.accessifyforum.com/viewtopic.php?t=4209

  • #6
    Jan
    Jan is offline
    Regular Coder
    Join Date
    Jul 2002
    Location
    Finland
    Posts
    204
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've asked the same some time ago and was pointed to this excellent post:
    http://www.youngpup.net/2003/popups

    If you want to open a link in a new window (which in my opinion should be avoided), simply use

    Code:
    <a href="http://www.yourlink.com/" onclick="window.open(this.href); return false;">Your link</a>
    Works like a charm.
    Last edited by Jan; 12-09-2005 at 01:44 PM.

  • #7
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by Jan
    If you want to open a link in a new window (which in my opinion should be avoided), simply use

    Code:
    <a href="http://www.yourlink.com/" onclick="window.open(); return false;">Your link</a>
    Works like a charm.
    Not without a url argument in the window.open method it doesn't.

    I guess you meant this…
    Code:
    <a href="http://www.yourlink.com/" onclick="window.open(this.href); return false;">Your link</a>
    …but even then, it's not a particularly efficient approach if you have many off-site links. Unless you like making work for yourself.

    God forbid we should ever have to do this for every new window link…
    Quote Originally Posted by the linked 2003 article
    Code:
    <a 
      href="http://google.com/" 
      onclick="window.open(this.href, 'popupwindow', 
      'width=400,height=300,scrollbars,resizable'); 
      return false;"
    >
    There are a number of other reasons why, imho, that method falls short of how we should be handling this kind of thing today.
    Last edited by Bill Posters; 12-09-2005 at 12:54 PM.

  • #8
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Here is one way without using target="_blank" of course it requires JS but if JS is disabled the use just gets taken to the page anyways in the same window.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <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.target = "_blank";
     }
    }
    window.onload=externalLinks;
    -->
    </script>
    </head>
    
    <body>
    <a href="http://www.codingforums.com" rel="external">Coding Forums</a>
    </body>
    </html>

  • #9
    Jan
    Jan is offline
    Regular Coder
    Join Date
    Jul 2002
    Location
    Finland
    Posts
    204
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Bill Posters
    Not without a url argument in the window.open method it doesn't.
    My mistake, sorry. This is what happens when I write in a hurry. Nevertheless, I seldom use forced window links and I can imagine a method like this would be very tiresome in the long run.

  • #10
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by _Aerospace_Eng_
    <a href="http://www.codingforums.com" rel="external">Coding Forums</a>[/code]
    Fine if you don't have many links to address and don't mind obtrusive js - or if not all your off-site links target new windows.

  • #11
    New Coder
    Join Date
    Dec 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    controlling window size without javascript

    Hi,

    I have something of a related problem. I have a link that I need to open in a new window. However, because of certain program limitations I can't use javascript. All I can do is use something on the order of _blank. Is there any way to control the size of the window that opens with this or any other html command?

    thanks

  • #12
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    No you need javascript to control the window size.

  • #13
    New Coder
    Join Date
    Dec 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    bah humbug,

    ok thanks for the heads-up, guess I can stop wasting my time on that one.

    tim


  •  

    Posting Permissions

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