SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Correct Way To Open Blank

  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    600
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Correct Way To Open Blank

    Hi,

    I am using the following code to open a blank page however this creates an HTML error.

    Does anyone know the correct code to open a blank page. Im sure this used to work fine.

    Code:
    target="_blank" class='venuelink'

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2012
    Location
    Scarborough, North Yorkshire, United Kingdom
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Run for cover!

    This no longer validates as it is considered bad practice. You are forcing the user to open a new window and you should really leave that decision up to the user. It also breaks back button functionality etc.

  3. #3
    SitePoint Wizard
    Join Date
    Oct 2005
    Posts
    1,594
    Mentioned
    3 Post(s)
    Tagged
    1 Thread(s)
    When you say "HTML error", are you referring to a validation error? target="_blank" is correct for HTML but is invalid for XHTML.

    http://www.w3schools.com/tags/att_a_target.asp

    If you are using XHTML, you will have to use Javascript to open your target in a new window in order for it to validate. Like this:

    Code:
    onclick="window.open(this.href,'_blank'); return false;"
    Complete link would be:

    Code:
    <a href="http://www.sitepoint.com/" onclick="window.open(this.href,'_blank'); return false;">Sitepoint</a>
    The "return: false;" part is important.

    You could also do something similar to this:

    http://www.thefutureoftheweb.com/blo...-blank-xhtml11

  4. #4
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    600
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <a href="http://www.sitepoint.com/" onclick="window.open(this.href,'_blank'); return false;">Sitepoint</a>
    Brilliant thanks, do I need to add anything to the head to allow it to recognise the Javascript?

    Im using it on a directory which a blank window would work better.

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2012
    Location
    Scarborough, North Yorkshire, United Kingdom
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try to use sparingly: Should links open in new windows - http://uxdesign.smashingmagazine.com...n-new-windows/

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
  •