Window.location with target="_blank"

how do I do

 window.location 

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

thank you…

I’m pretty sure target=‘_blank’ is deprecated.

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

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…

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 :wink:

The red bit is just simply not true at all :lol:

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.

@maya90

and this is it:

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…;~)

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.