Results 1 to 4 of 4

Thread: Target=“_blank” vs window.open

  1. #1
    Join Date
    Nov 2009
    Posts
    211
    Thanks
    40
    Thanked 1 Time in 1 Post

    Default Target=“_blank” vs window.open

    I'm working on an application where users enter some input and they shouldn't leave the page when clicking on share links, e.g. a Facebook share link:
    Code:
    <a href="https://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.example.com%2F">Share on Facebook</a>
    I know it's very common to use popup windows for such links. But does it have any advantage over a simple target="_blank" attribute? How do you compare the two methods and which is the right practice in such cases?

  2. #2
    Join Date
    Nov 2006
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    689
    Thanks
    1
    Thanked 113 Times in 111 Posts

    Default

    Hi there Rain Lover,

    The target="blank" attribute has two advantages that come to mind...

    1. it does not require javascript
    2. it is not affected by pop-up blockers

    coothead

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,991
    Thanks
    43
    Thanked 3,198 Times in 3,160 Posts
    Blog Entries
    12

    Default

    Popup blockers will block target="_blank" if the settings are strict enough. In fact, since window.open will not usually be blocked if activated by a click action of the user (it will be blocked, again, if the settings are strict enough), these are about equivalent in that department. It's correct that target doesn't require javascript. Using window.open allows (though does not require) one to use specifications. Although many of these are now ignored by most browsers as a matter of course, most still allow specification of width, height, top and left, and sometimes a few other things. These can be handy.

    However, in most cases it's overall bad form to open a new window. The user can do this his/her self, if desired. If the new content is such that it should not change the root page in the browser, it can often be introduced via AJAX, and/or a popup div, and/or an iframe. If it is from another site, best to leave that (decision as to where to open it) to the user. Otherwise you might inadvertently violate TOS and/or copyright.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. The Following 2 Users Say Thank You to jscheuer1 For This Useful Post:

    Rain Lover (07-02-2014),vutaikt (07-30-2014)

  5. #4
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,363
    Thanks
    31
    Thanked 140 Times in 135 Posts
    Blog Entries
    32

    Default

    Quote Originally Posted by jscheuer1 View Post
    If the new content is such that it should not change the root page in the browser, it can often be introduced via AJAX, and/or a popup div, and/or an iframe. If it is from another site, best to leave that (decision as to where to open it) to the user. Otherwise you might inadvertently violate TOS and/or copyright.
    Yes, my beloved iframe. TOS-issues can be taken care of by explicitly mentioning the foreign URL. Here's a crazy idea:
    Code:
    <div id="popup_frame" style="font-family: verdana; font-size: 12px; "></div>
    <a href="javascript: void(0)" onclick="document.getElementById('popup_frame').innerHTML='<div style=\'position: absolute; left: 0px; top: 25px; right: 0px; bottom: 0px\'><div style=\'position: relative; float: right; cursor: pointer; background: darkred; color: white; font-weight: bold; font-size: 13px; top: -25px\' onclick=\'document.getElementById(&quot;popup_frame&quot;).innerHTML=&quot;&quot;\'>&nbsp;X&nbsp;<\/div><br><iframe id=\'ifr\' src=\'http://dynamicdrive.com\' style=\'position: absolute; width: 100%; height: 100%; border: 1px solid black; margin-left: -1px\' frameborder=\'0\'><\/iframe><\/div>'; document.getElementById('popup_frame').innerHTML='<div style=\'position: absolute; left: 10%; top: 10%; right: 10%; bottom: 10%; background: #dedede; color: black;  border: 1px solid black; border-bottom:0\'>'+'<div style=\'position: absolute;  text-align: center;height: 35px; left:50px; top: 5px; right: 50px; overflow-y: auto;overflow-x: hidden; z-index: 1;  \'>'+document.getElementById('ifr').src+'<\/div>'+document.getElementById('popup_frame').innerHTML+'<\/div>'">popup DD</a>

  6. The Following User Says Thank You to molendijk For This Useful Post:

    vutaikt (07-30-2014)

Similar Threads

  1. Flexi Slide Show: target=_blank or _new
    By carolinawebdesign in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 09-08-2010, 09:21 AM
  2. 'small' window target="_blank"
    By northyukon in forum JavaScript
    Replies: 2
    Last Post: 02-06-2010, 09:55 PM
  3. Carousel II (2) Open Target in SAME window
    By npimpfellow in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 05-01-2009, 03:36 AM
  4. target _blank does not function. Why?
    By anne oosterhaven in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 01-17-2005, 09:11 PM

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
  •