Wednesday, August 12, 2009

Hyperlink: Difference between target="new" and target="_blank"

If you are not familiar with the HTML hyperlink tab <a>, go first read anchor text and how to make hyperlink open in new window or tab and/or making active (clickable) hyperlink in posts and comments. Please take note that the target attribute has been deprecated and will not pass W3C XHTML 1.0 Strict validation. So if W3C validation is important to you, you should not use the target attribute.

To make hyperlink open in new tab or window, one uses either the target="_blank" or target="new" or target="anything" where anything is exactly that, any word, even meaningless one like "abtjsgj". Now I have received query what is the difference between them. Before publishing this post, I have tested the hyperlinks with different attribute at testing target attributes for hyperlinks where you can try out the links yourself.

When you use the target="_blank" attribute for the hyperlink <a> tag, all links with that attribute will open in new windows or tabs. When you use the target="new" or target="anything" attribute, the first click on any link with that attribute will open in a new window called new or anything. Any subsequent click on any link with that attribute will open in the same window called new or anything.

39 comments:

  1. i'm sorry ... i'm completely lost. what is w3c validation? cos i'm using target="_blank" now in my blog... so i want to know if that's illegal. thanks :)

    ReplyDelete
  2. Hi Peter,
    Thanks for the response. I have one pending post / response from you (about 'NEW' tag to the latest posts). Please post this trick if you find time.
    Thanks
    college2job.blogspot.com

    ReplyDelete
  3. my blog

    http://adiraijamal.blogspot.com

    has been deleted

    associated account

    dubai.jamal@gmail.com

    has also been deleted.

    can you assist this please.

    atleast I wish to have

    adiraijamal.blogspot.com

    Please assist.

    Contact me @


    sg.jamal@gmail.com


    thanks & regards.

    ReplyDelete
  4. Did you delete your email (gmail) address?

    ReplyDelete
  5. College2Job,

    Sorry don't understand. What is this NEW? New comments? New posts?

    ReplyDelete
  6. W3C validation? Illegal? Worried you get arrested by police?

    No fear. W3C is www (world wide web) consortium setting standards and if what you put in your blog does not comply with their standard, then it will show as error. So using the target attribute will be shown as an error but currently will still be displayed and will still function. Your blog will not explode.

    More about this if you are interested later if I feel the urge.

    ReplyDelete
  7. HAHAHA!!! thank you :)) yea... i went and researched on it as well ... and phew ... no explosion is good!!

    ReplyDelete
  8. Hi Peter 1, from Peter 2! I've appreciated your latest posts about hyperlinks. I've become so lazy using Windows Live Writer, (blessing in disguise) in regards to this, that it is good to get back to basics here!

    Take Care,
    Peter
    Sydney Australia

    ReplyDelete
  9. Many thanks for this. I have a related question. I am currently using the Twitter Updates gadget within blogger.

    Seems to work fine and shows me the latest updates from twitter.

    However, when I go click on a URL within one of these updates then it tries to display the link within a mini window on my side-bar and not by opening a new window.

    Since I don't have control of the HTML within the gadget, how do I make the change necessary to display these links in a new window ?

    Many thanks for all your help.


    James

    ReplyDelete
  10. I have no experience with Twitter gadget so can't help.

    ReplyDelete
  11. Thanks, I understand the difference between 'blank' and 'new'

    aR
    Bangla Hacks

    ReplyDelete
  12. hi... i was given your blog to go to for help because i am having some blog problems and im a bit annoyed that i cant contact blogger!

    please help me if you can...

    none of my followers get updated in the blog reader when i post and im not sure what is going on or how to fix this?

    can you help?
    does it have anything to do with changing my blog name?

    i would sooo appreciate your help. thank you!!!

    ReplyDelete
  13. I have read many reports of problems with Blogger followers gadgets which is known problem and Blogger says they are in the process of fixing. It has been months and apparently this is still a problem.

    ReplyDelete
  14. Hi Peter,
    I want to indicate new posts and links with 'NEW' tag as like in http://helpbiotech.blogspot.com/
    (you can find blinking 'new' indications on left sidebar of this blog)
    Thanks a lot for your valuable tips and tricks
    college2job.blogspot.com

    ReplyDelete
  15. I have tried numerous times to have post images..both hosted by outside of Blogger and uploaded to blogger, open in a separate window...to no avail. Can you check out the top post and let me knowwhat it does not work please? When I do what you describe-the text target="blank" shows up in my post. I feel I will lose the reader if they continually have to hit the "back" button

    Thanks

    Steve J
    http://winstontrails.blogspot.com/

    ReplyDelete
  16. Not sure if I understood you or your problem, but if you are trying to use <a href="URL" target="_blank"><img></a> then clicking on the image will result in a new tab or window opening. Note that it is target="_blank" instead of target=blank

    ReplyDelete
  17. This comment has been removed by the author.

    ReplyDelete
  18. Ok, I appreciate the clarification, so "_blank" always pops open a new window or tab every time, while "new" allows for only one extra window to open but the same one window will be re-used if another "new" target is clicked on.

    However, the million dollar question is "which is better?" target="new" or target="_blank"?

    ReplyDelete
  19. I suppose that will depend on the purpose of making links open in "new" window, not a question of which is better. Perhaps blogger who expect visitors to often click on links may not want to irritate visitors on too many windows being opened.

    ReplyDelete
  20. I just wanted to add a point of clarification. There is nothing special about the word "new" in this context. It is not a keyword. Any word other than "_blank" will work exactly the same.

    In fact, you could actually use more than one word if you wanted to make sure that all clicks on certain kinds of links always opened in one new window and all clicks on other kinds of links always opened in a different new window.

    For example all external links could be targeted to "atarashiexternal" and all internal links could be targeted to "nuevointernal".

    I just wanted to point out that the word "new" has no special meaning for the attribute "TARGET".

    ReplyDelete
  21. Hi James,

    Thanks for the clarification. The post has been updated to make the point clearer.

    ReplyDelete
  22. When using "_blank" for a .pdf file to load into, the new tab title seems to get the underlying file name of the .pdf file, which isn't particularly useful or friendly. Any way to directly control the tab title when using "_blank"?

    (It sounds from your description like using "anything" would give you the chosen title, but I'm not looking for the "anything" behavior.)

    Thanks!

    ReplyDelete
  23. Can you please explain what you mean by "tab title"? Are you referring to the anchor text?

    ReplyDelete
  24. Sorry for not having a better term. No, not the anchor text. For example, my browser is set to open new "windows" in a new tab instead. There's some text in the tab itself - which I assume would be the title of the new window if it opened in a new window. With the "=whatever" syntax, the "whatever" becomes the title. But with "_blank" when opening a .PDF file, it uses the literal file name in the system as the title. I'd like to override that with something else.

    ReplyDelete
  25. Ah you mean the text in the browser tabs? Now I am at the moment viewing one of my post Create subdomain with custom domain and what I see in the browser tabs is "Create sub-domoan....."

    So what is the problem?

    ReplyDelete
  26. Yes, it's about the text in the browser tabs, but it isn't about subdomains here, it's a general question about opening pdfs in a new tab using target=_blank.

    ReplyDelete
  27. I used that post as an example of how we can get the post title to appear first before the blog title which is what I guessed you want? If that is what you want, refer to SEO tip: increase traffic, display post title before blog title

    ReplyDelete
  28. Very interesting post. I always wondered about this. Thanks for clearing things up!

    ReplyDelete
  29. You can still use XHTML strict and target hyperlinks and yes still have it pass with W3C validation. You can do this with Javascript between your heading tags you place this code:

    $(function(){
    $('a[rel="external"]').attr('target','_new');
    });

    Then in every link you want to target the new window add rel="external" to the anchor. That will reference the javascript function and open it in a new window and all of which will validate in W3C as XHTML strict. Hope this helps.

    ReplyDelete
  30. How to open hyperlinks in new tab with IE 7 or more??

    ReplyDelete
  31. Just found out about Links in will not open a new window or tab in Windows 7 IE8 and it looks like one will have to wait for MS to work out the solution.

    ReplyDelete
  32. Hey, do you know how to make a photo hyperlink open in the same tab?

    ReplyDelete
  33. If you want a hyperlink to open in the same tab/window, just don't add that target="_blank" to the hyperlink tag.

    ReplyDelete
  34. thx for the very clear explanation

    ReplyDelete
  35. Hi. I looks like I can't use <a href in the Sidebar? Invalid... can't use target_ why is that?

    ReplyDelete
  36. You can use the hyperlink tag in comments but NOT make it open in new tab or window, ie. no target="_blank"

    ReplyDelete
  37. i have opened domain1.com in a window. from a link in domain1.com i open domain2.com in another new window. now from that domain2.com link can i focus to the same domain1.com tab. please let me know.

    ReplyDelete
  38. i have opened domain1.com in a new window.from a link in domain1.com i open domain2.com in new window. from a link in domain2.com can i link back to the same opened domain1.com instead of a opening the domain1.com in new window.
    Please let me know. thanks in advance.
    Your "new" solved my Problem1 and remaining is this above stated problem.

    ReplyDelete
  39. Sorry don't understand what you want

    ReplyDelete

Find help, info, instructions, tips, tricks

Tip: Use search box below or this box, labels in the first right sidebar, archive, ctrl+F for this page or sitemap to find topics