Opening New Window in HTML for Target="_Blank"

Target _blank not opening new window

Your syntax for the target attribute is correct, but browsers need not honor it. They may interpret it as opening the destination in a new tab rather than new window, or they may completely ignore the attribute. Browsers have settings for such issues. Moreover, opening of new windows may be prevented by browser plugins (typically designed to prevent annoying advertisements).

There’s little you can do about this as an author. You might consider opening a new window with JavaScript instead, cf. to the accepted answer to target="_blank" is not working in firefox?, but browsers may be even more reluctant to let pages open new windows that way than via target.

target=_blank does not open new window

When you click the button, the code fires immediately, and so your code is navigating to another page but in the same tab.

target="_blank" works only if the form has an action to send the data to.

use window.open(url) instead.

function process() {  var url = "https://myurl.com/products/" + document.getElementById("url").value.trim();  window.open(url);  return false;}
<form onSubmit="return process();" target="_blank">  <input type="text" name="url" id="url" placeholder="Product ID"> <input type="submit" value="Search"></form>

Target='_blank' to show in new window, NOT new tab, possible?

You cannot control this - it's entirely at the discretion of the user-agent; which is the point, after all. All you can specify is that the page be opened in a different viewpane context, and it's up to the user to decide how they want your window to take up their screen space/taskbar list/Alt-Tab shortcuts etc.

In fact I'd go even further and say that if at all possible you should avoid opening up a new tab/window at all. I know that I get a little annoyed when websites do this, and it feels a bit clunky and 1990s what with all the Ajax and floating divs and magic we have nowadays.

Make a link open a new window (not tab)

With pure HTML you can't influence this - every modern browser (= the user) has complete control over this behavior because it has been misused a lot in the past...

HTML option

You can open a new window (HTML4) or a new browsing context (HTML5). Browsing context in modern browsers is mostly "new tab" instead of "new window". You have no influence on that, and you can't "force" modern browsers to open a new window.

In order to do this, use the anchor element's attribute target[1]. The value you are looking for is _blank[2].

<a href="www.example.com/example.html" target="_blank">link text</a>

JavaScript option

Forcing a new window is possible via javascript - see Ievgen's excellent answer below for a javascript solution.

(!) However, be aware, that opening windows via javascript (if not done in the onclick event from an anchor element) are subject to getting blocked by popup blockers!

[1] This attribute dates back to the times when browsers did not have tabs and using framesets was state of the art. In the meantime, the functionality of this attribute has slightly changed (see MDN Docu)

[2] There are some other values which do not make much sense anymore (because they were designed with framesets in mind) like _parent, _self or _top.

HTML: how to force links to open in a new tab, not new window

There is no way to do that as the author of the HTML that a browser renders. At least not yet that I know of. Its pretty much up to the browser and its settings / preferences that are set by users themselves.

Also, you shouldn't impose this upon any user. A browser is the user's property. If a user wants to open all links in tabs or in new windows, then let the user do exactly that.

It's good that we can't do certain things. target=_blank is still abused and popups have been done to death.

target=_blank opens a new window in IE9, instead of a new tab

HTML and JavaScript provide no means to say if a new "window" should be a full window, or a tab, or whatever you want to call the Mobile Safari multiple views interface.

So you live with it.

base target=_blank in head does not open links in new tab or window

"The issue is due to vc_gitem-link class which does not support opening the link in a new tab. You can target it html custom js to remove the class added to it." This was the answer of the Visual Composer plugin developers.



Related Topics



Leave a reply



Submit