SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    813
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    window.location with target="_blank"

    how do I do

    Code:
     window.location

    but have it open in new browser window (like with target="_blank", not window.open)

    thank you..

  2. #2
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm pretty sure target='_blank' is deprecated.

    window.open() is the way it is supposed to be done.

  3. #3
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    813
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    target="_blank" is not deprecated (I think... I mean it validates with transitional doctype if you set it in conventional way in <a> tag.. )

    but prob is, for window.open you HAVE to set dimensions and all that other stuff... I guess I could say make it same dimensions as current window.. oh brother...
    besides which, with window.open() you have issue of pop-up blockers...

    ok.. thanks...

  4. #4
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by maya90 View Post
    target="_blank" is not deprecated (I think... I mean it validates with transitional doctype if you set it in conventional way in <a> tag.. )
    deprecated means it is intended to not support it in the future. It doesn't mean it isn't supported now, and there is a reason why it might validate in transitional and not Strict


    Quote Originally Posted by maya90 View Post
    for window.open you HAVE to set dimensions and all that other stuff...
    The red bit is just simply not true at all

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,785
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by webdev1958 View Post
    deprecated means it is intended to not support it in the future. It doesn't mean it isn't supported now
    It means that it is intended to be dropped completely from the next version. The purpose of deprecating something is so that people have time to go through all of the spots where they currently use the deprecated code and change it before the next version comes out.

    The purpose of transitional doctypes is to allow people to transition from one version to the next. The HTML 4 transitional doctype provides a way for web pages using HTML 3.2 to start using the any new HTML 4 tags while gradually getting rid of all the HTML 3.2 tags that have been deprecated. The problem is that people are creating new web pages using the transitional doctype which was not what it was created for. New pages should be created using the HTML 4 strict doctype as there is no reason whatever for using tags that were flagged in 1997 as being obsolete and to be removed from the next version.

    Unfortunately those creating HTML 5 have decided to riscind the 1997 decision to remove the unnecessary garbage tags.

    As for target="_blank" - the reason it was flagged for removal from HTML back in 1997 is that it reduces your visitors options as to where the link should open. Without that attribute your visitor can choose whether they want the page to open in the same window, a new window, or a new tab simply by right clicking on the link and selecting one of the three options. Adding that attribute removes one of the three choices while still not giving the web page author any control over which of the other two options will be applied meaning that neither party has control over where the window opens any more.

    Using window.open instead of the target attribute restores that choice back to the person whose browser it is as they have full control over what JavaScript runs and so they can have the new page open where they want. The parameters in the window.open statement are optional and browser settings can override most of them giving the control back to the browser owner.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @maya90

    Quote Originally Posted by webdev1958 View Post
    deprecated means it is intended to not support it in the future..........and there is a reason why it might validate in transitional and not Strict
    and this is it:

    Quote Originally Posted by felgall View Post
    ......... The purpose of deprecating something is so that people have time to go through all of the spots where they currently use the deprecated code and change it before the next version comes out.

    The purpose of transitional doctypes is to allow people to transition from one version to the next. ............

  7. #7
    SitePoint Guru
    Join Date
    Jun 2009
    Posts
    813
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    thank you all for your responses.. in the end just set href attr in jQuery and kept target=_"blank" in <a> tag... a very obvious solution suggested by a colleague.. I can't believe I hadn't thought of it myself...

    yes I know some people feel target="_blank" shouldn't be used, but well, we gotta do what our clients want... (target="_blank" can also be set in JavaScript, of course, but it won't work JS is disabled...)

    thank you very much..

    PS: pls also note that links included in posts like this right here in Sitepoint fora also open in a new window....;~)

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,785
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by maya90 View Post
    we gotta do what our clients want...
    Of course as the professional you should be advising them that it will make their page less usable and drive away visitors. You should then do it on the basis that they are trying to drive some of their visitors to their competition.

    Of course the more knowledgeable visitors will have turned off the target attribute in their browser so that it will not do anything anyway.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •