SitePoint Sponsor

User Tag List

Results 1 to 22 of 22
  1. #1
    Forensic SEO Consultant Webnauts's Avatar
    Join Date
    Jun 2003
    Location
    European Union
    Posts
    1,488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Don't Open New Windows

    Actually you should not force links to open in a new window or popups (such as with the "target" attribute or with JavaScript).

    Changing the current window or popping up new windows can be very disorienting to users who cannot see that this has happened.

    As you might also know, JavaScript is not supported by all browsers and some users disable it. When JavaScript is used, it should not be relied upon.

    Another fact is, that if you markup with XHTML Strict, the "target=_blank" is not supported!

    If you absolutely must open a link in a new window, explicitly warn the user with a clear indication that the page will open in a different window. Provide a title attribute on the anchor tag with a description indicating that the link opens a new window; for example:

    <a href="<A href="http://www.eypd2003.org">http://www.eypd2003.org" target="_blank" title="Link opens in new window.">European Year of People with Disabilities 2003 (new window)</a>

    If you want to build an accessible pop-up window, add the code below within the head tags of your HTML document:

    <script type="text/javascript">
    var newWindow = null;
    function closeWin(){
    if (newWindow != null){
    if(!newWindow.closed)
    newWindow.close();
    }
    }
    function popUpWin(url, type, strWidth, strHeight){
    closeWin();
    if (type == "fullScreen"){
    strWidth = screen.availWidth - 10;
    strHeight = screen.availHeight - 160;
    }
    var tools="";
    if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
    if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
    newWindow = window.open(url, 'newWin', tools);
    newWindow.focus();
    }
    </script>

    Above script source: http://www.accessify.com

    Then add your link in the body of your document as below:
    <a href="<A href="http://www.w3.org/WAI/">http://www.w3.org/WAI/" onclick="popUpWin(this.href,'standard',640,480);return false;" onkeypress="popUpWin(this.href,'standard',640,480);return false;" title="Link open's in a new window">Web Accessibility Initiative (WAI)</a>

    Example see here: http://www.webnauts.net/popup.html

    Test this turning off JavaScript to see how it works!

    Further reading:

    Not opening new windows: http://diveintoaccessibility.org/day...w_windows.html
    Use interim solutions: http://www.w3.org/TR/WCAG10/#gl-interim-accessibility
    Opening a link in a new window: http://lists.w3.org/Archives/Public/...2Apr/0100.html
    If you still have questions, please feel free to post them.

  2. #2
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Personally, I prefer target="_blank" because it is a standard method. If I know a link will open in a new window (such as a link in a form post), and I want it to open in the current window, I can just override the target by right clicking and selecting "open". It will allways open in link in the same window.

    The JS hack makes my life harder, because it is less predictable.

    Douglas
    Hello World

  3. #3
    Forensic SEO Consultant Webnauts's Avatar
    Join Date
    Jun 2003
    Location
    European Union
    Posts
    1,488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DougBTX
    Personally, I prefer target="_blank" because it is a standard method. If I know a link will open in a new window (such as a link in a form post), and I want it to open in the current window, I can just override the target by right clicking and selecting "open". It will allways open in link in the same window.

    The JS hack makes my life harder, because it is less predictable.

    Douglas
    And how would you legally open a new window, if you code with XHTML Strict?

  4. #4
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wouldn't. I'd use Transitional. My users are more important than which doctype I use.

    Douglas
    Hello World

  5. #5
    SitePoint Evangelist ucahg's Avatar
    Join Date
    Apr 2001
    Location
    Sarnia, Ontario, Canada
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DougBTX
    My users are more important than which doctype I use.
    Agree. While aiming for strict XHTML isn't a bad thing at all, XHTML (be it strict, or transitional), and CSS are just technologies, and should not be the focus of the web developer. Rather the users should (if you can do this with XHTML 1.1, more power to you, but if you need 1.0 transitional, or even HTML 4 in order to make the best sight for your users, that should be the focus.
    Love it? Hate it? Helpful? Useless?
    Use the rate button to let me know what you think of my post!

  6. #6
    SitePoint Zealot HardinComp's Avatar
    Join Date
    May 2003
    Location
    Boston, MA
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Webnauts
    And how would you legally open a new window, if you code with XHTML Strict?
    You can legally include this in your anchor tag:
    Code:
    onclick="this.target='links';"
    That vaidates with no problem.
    J.M. Hardin
    My blog
    Registered Ubuntu User #10980

  7. #7
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by HardinComp
    You can legally include this in your anchor tag:
    Code:
    onclick="this.target='links';"
    That vaidates with no problem.
    It passes automated validation tools yes, but you're not supposed to use target in XHTML Strict so it's still against the spirit of strict coding.

  8. #8
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vgarcia
    It passes automated validation tools yes, but you're not supposed to use target in XHTML Strict so it's still against the spirit of strict coding.
    Technically it is valid, because this.target is defined in the DOM, not in HTML/XHTML. But still, I would use the target attribute before using JS, if I was opening new windows atall.

    Douglas
    Hello World

  9. #9
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by DougBTX
    Technically it is valid, because this.target is defined in the DOM, not in HTML/XHTML. But still, I would use the target attribute before using JS, if I was opening new windows atall.

    Douglas
    If I had to open new windows AND code in Strict (which is a scenario I'll probably never see), I'd more likely use window.open() than this.target. However, it's most likely that I'd just drop into Transitional and use _blank if I really needed to open links in new windows, so yeah I agree with ya .

  10. #10
    SitePoint Zealot johno's Avatar
    Join Date
    Sep 2003
    Location
    Bratislava, Slovakia
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I'm missing something here: Is there any good reason for opening a document in a new window?

  11. #11
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by johno
    I think I'm missing something here: Is there any good reason for opening a document in a new window?
    It depends on the type of site and/or content you have, but usually it's not a good idea.

  12. #12
    Ensure you finish what you sta bronze trophy John Colby's Avatar
    Join Date
    Aug 2003
    Location
    University of Central England, U.K.
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by johno
    I think I'm missing something here: Is there any good reason for opening a document in a new window?
    I agree with Vinne - it's not a good idea. I get asked question about this, and ask people why they feel it is necessary to open up a new window for their paricular purpose - and to date I haven't found anyone gives me a sufficiently convincing reason. I could bang on about accessibilty here - not only for visually impaired users but also those on limited memort devices such as PDAs and mobile phones - which is an increasing market.

    The limited memory is important because opening a new window is memory hungry - and you soon run out an your site may not appear to work because you've choosen that route - and that person you lose may be a customer.
    John
    No electrons were harmed during the creation, transmission
    or reading of this posting. However, many were excited and
    some may have enjoyed the experience.

  13. #13
    SitePoint Zealot johno's Avatar
    Join Date
    Sep 2003
    Location
    Bratislava, Slovakia
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John Colby
    ...ask people why they feel it is necessary to open up a new window for their paricular purpose - and to date I haven't found anyone gives me a sufficiently convincing reason.
    This is it. Everyone is annoyed about the missing target="_blank" in xhtml strict but noone can tell why it is so "important".

  14. #14
    SitePoint Zealot HardinComp's Avatar
    Join Date
    May 2003
    Location
    Boston, MA
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by johno
    I think I'm missing something here: Is there any good reason for opening a document in a new window?
    I used it for a page about a benefit concert I worked with to show information about an artist in a smaller window. This allowed my users to get a little info about a specific artist without leaving the page. After the event I looked at the stats and found some artist windows got more traffic than others, and I think next time I do a page like that I'll keep the "artist window" concept. I like the idea of giving the info without having to go back to the main concert info page.
    J.M. Hardin
    My blog
    Registered Ubuntu User #10980

  15. #15
    SitePoint Zealot ComputerBob's Avatar
    Join Date
    Jul 2003
    Location
    USA
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I used target="_blank" on my Web site for the past 5 years, to open external links in new windows. My users found it easier to understand than if I had just linked to external sites in the same window. Plus, it allowed them to return to my site from external sites by simply closing the window that contained the external site.

    With all that said, I'm in the final stages of my site redesign, and one of the things that I did was stop using target="_blank," for accessibility and user-control reasons. My new design is XHML 1.0 Strict, and uses a CSS class to put a dashed-underline

    (see http://www.sitepoint.com/newsletter/...&format=html#6)

    under external links, thereby giving users the choice to open those links in a new window if they desire.
    ComputerBob - Making Geek-Speak Chic™
    http://www.computerbob.com
    - XHTML 1.0 Strict + CSS Layout
    Ratings | Forums | Software | Polls | Weird | Quotes | Weather
    Guest Articles | Free Greeting Cards | CB Awards | Search

  16. #16
    Forensic SEO Consultant Webnauts's Avatar
    Join Date
    Jun 2003
    Location
    European Union
    Posts
    1,488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ComputerBob
    I used target="_blank" on my Web site for the past 5 years, to open external links in new windows. My users found it easier to understand than if I had just linked to external sites in the same window. Plus, it allowed them to return to my site from external sites by simply closing the window that contained the external site.

    With all that said, I'm in the final stages of my site redesign, and one of the things that I did was stop using target="_blank," for accessibility and user-control reasons. My new design is XHML 1.0 Strict, and uses a CSS class to put a dashed-underline

    (see http://www.sitepoint.com/newsletter/...&format=html#6)

    under external links, thereby giving users the choice to open those links in a new window if they desire.
    Excellent post and link! Thanks!

  17. #17
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    Ah yes, since the humble PDA has been discussed then using target="_blank" would be very bad idea indeed and JavaScript cannot be relied on to create the popup.

    Though in either case you should provide a page that can be accessed if either of the two methods were unavailable to the user-agent.

    Why people get upset about (x)html "target" attribute disappearing from XHTML Strict 1.0 onwards is because it could also be referenced via scripting languages in either case the target was specifically designed for the Frameset rather than Transitional.

  18. #18
    Forensic SEO Consultant Webnauts's Avatar
    Join Date
    Jun 2003
    Location
    European Union
    Posts
    1,488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  19. #19
    SitePoint Zealot johno's Avatar
    Join Date
    Sep 2003
    Location
    Bratislava, Slovakia
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I am forced to do popup window I use this peace of JS.

    Code:
    function showPopup(href) {
    	var newWindow = window.open(href, "name", "params");
    
    	if(!newWindow) return false;
    	return true;
    }
    And then in (X)HTML
    Code:
    <a href="galeria.php?neco=neco" onclick="return !showPopup(this.href);">
    This will enable opening page also in that case that users have blocked opening popups or do not have JS.

  20. #20
    Forensic SEO Consultant Webnauts's Avatar
    Join Date
    Jun 2003
    Location
    European Union
    Posts
    1,488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    johno would your code validate with Bobby or so?

  21. #21
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Webnauts
    johno would your code validate with Bobby or so?
    From the looks of it, yes. If Javascript isn't available when viewing that page, it will just open it up in the same window.

  22. #22
    Forensic SEO Consultant Webnauts's Avatar
    Join Date
    Jun 2003
    Location
    European Union
    Posts
    1,488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Some more interesting resources on this topic:

    Well mannered JavaScript: http://smallinitiatives.com/journal95_0_1_0_C.html

    Also see here:

    Links & JavaScript Living Together in Harmony: http://evolt.org/article/Links_and_JavaScript_Living_Together_in_Harmony/17/20938/


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
  •