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 6 of 6
  1. #1
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,090
    Thanks
    2
    Thanked 23 Times in 23 Posts

    The case for not opening a link in a new window

    I almost feel stupid for asking this, but here goes.

    For a long time, I have heard that it is considered best practice not to code a website so that hyperlinks would automatically open in a new window; i.e., don't code them with target="_blank" and to let the site visitor decide for themselves if they want to open up a new window or not. Now I find myself in the position of needing a "good" reason I can give to a non-techie-type user why this is so.

    Here's a little background: We just deployed a new version of our website at work, converting the code from classic ASP to ASP.NET. While we did this, we took out all the target="_blank" stuff from the pages. Now, we have someone complaining because we altered the functionality of the website; i.e., we no longer have links open in a new window. I need to come up with a good enough reason they will buy so we don't have to re-code a bunch of pages to open in a new window.

    What words of advice can you offer?
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    If you have some way to capture those links(say, have some special class OR have some other attribute like rel OR they are the links contained inside a special wrapper element ) in javascript, then you could apply the window.open() or the target attribute to them.
    eg:
    Code:
    function setTarget(){
    	var links=document.getElementsByTagName('a');
    	for(var i=0;i<links.length;i++)
    		if(links[i].getAttribute('rel')=="targetBlank")
    			{
    			links[i].onclick=function(){
    				var blankWin = window.open(this.href,'_blank','menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes');
    				return false;
    				}
    			links[i].setAttribute('title','will be opened in a new window!');
    			}
    }
    window.onload= function(){
    setTarget();
    The above code will open all the links having rel="targetBlank" in new windows, provided there is javascript support in browser
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder FWDrew's Avatar
    Join Date
    Apr 2008
    Location
    Missouri
    Posts
    380
    Thanks
    38
    Thanked 45 Times in 43 Posts
    Abduraooft has provided an excellent solution, but the debate rages on. It really is a matter of preference as to open a new window/tab or not. I will offer my opinion

    I feel that it should be the users choice how their tabs and windows open, and such feel that links should not open in a new window/tab. If I want to open a site in a new tab, I will simply right click and choose to do so.

    Just my two cents,

    Drew
    Dev-Tips.com || Employee at the Envato Network || My Portfolio

  • #4
    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
    A good read here on a possible solution that goes along with the idea of giving the user a choice.

    http://dev.akabillposters.com/dom-js...-links-jquery/
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • The Following 2 Users Say Thank You to _Aerospace_Eng_ For This Useful Post:

    oesxyl (11-19-2008), vinyl-junkie (11-19-2008)

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by vinyl-junkie View Post
    I almost feel stupid for asking this, but here goes.

    For a long time, I have heard that it is considered best practice not to code a website so that hyperlinks would automatically open in a new window; i.e., don't code them with target="_blank" and to let the site visitor decide for themselves if they want to open up a new window or not. Now I find myself in the position of needing a "good" reason I can give to a non-techie-type user why this is so.

    Here's a little background: We just deployed a new version of our website at work, converting the code from classic ASP to ASP.NET. While we did this, we took out all the target="_blank" stuff from the pages. Now, we have someone complaining because we altered the functionality of the website; i.e., we no longer have links open in a new window. I need to come up with a good enough reason they will buy so we don't have to re-code a bunch of pages to open in a new window.

    What words of advice can you offer?
    there are two criteria I use for deciding when I open in same window/tab and when not:
    - is internal link or not => external links - open in a new window/tab
    - I want the visitor to come back to previous page => open in new window/tab

    regards

  • #6
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,090
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Thanks, everyone, for your input. It is much appreciated.

    Aero, I especially like one particular paragraph on the page you linked to:

    Those who oppose this practise [opening a new window] argue that evidence from usability tests demonstrates that some users can become disoriented by the appearance of a new window and confused by the fact that they cannot use the 'Back' button in the new browser window to navigate back to the original website. It is for these reasons that some developers feel that creating new windows is a practise which should be avoided.
    I think I've found my reason to try and persuade this person not to add the "new window" code back into our pages. We are state government, and if I'm not mistaken, I believe we are required to make our website accessible to persons with disabilities. The above paragraph makes a very good case for accessibility, in my opinion.

    Thanks once again to everyone for your input.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!


  •  

    Posting Permissions

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