poltpie.blogg.se

New tab redirect
New tab redirect




  1. #New tab redirect code
  2. #New tab redirect windows

I'm going to agree somewhat with the person who wrote (paraphrased here): "For a link in an existing web page, the browser will always open the link in a new tab if the new page is part of the same web site as the existing web page." For me, at least, this "general rule" works in Chrome, Firefox, Opera, Internet Explorer, Safari, SeaMonkey, and Konqueror.Īnyway, there is a less complicated way to take advantage of what the other person presented. In order to behave like an actual 'mouse click' on a link, you need to follow spirinvladimir's advice and really create it: document.getElementById("nav-questions").setAttribute("target", "_blank") ĭocument.getElementById("nav-questions").dispatchEvent((function(e)(document.createEvent('MouseEvents')))) ĭocument.getElementById("firing_div").onclick = fire_custom_click In this page, open a JavaScript console and type: document.getElementById("nav-questions").setAttribute("target", "_blank") ĭocument.getElementById("nav-questions").click() Īnd it will try to open a popup regardless of your settings, because the 'click' comes from a custom action.

new tab redirect

This has nothing to do with browser settings if you are trying to open a new tab from a custom function. To bypass the popup blocker and open a new tab from a callback, here is a little hack: const button = document.querySelector('#openTab') However, if you try to open a new tab from an AJAX request callback, the browser will block it as it was not a direct user action. If it is called as a direct result of a user action, let us say a button click, it should work fine and open a new tab (or window): const button = document.querySelector('#openTab') Window.open() behaves differently depending on how it is being used. There is no way to override it in JavaScript.

new tab redirect

Whether to open the URL in a new tab or a new window, is actually controlled by the user's browser preferences. In Chrome, it seems window.open opens a new tab when it is used in an onclick event, and a new window when it is used from the browser console ( as noted by other people), and pop-ups open when a width and height are specified.Īdditional reading: window.open documentation.

#New tab redirect code

However, in Internet Explorer 11 the same code will always open a link in a new tab if tabs is chosen in the browser preferences, specifying a width and height will not force a new window popup.

#New tab redirect windows

In Chrome and Firefox, specifying a width and height will force a popup (as mentioned in the answers here), even when a user has set Firefox to open new windows in a new tab let url = '' Although, some ways to do it (editing the registry) are discussed in this question. It looks like Chrome (version 34) does not have any settings for choosing to open popups in a new window or a new tab.

new tab redirect

You can also set the tab preference to open new windows, and see the same results. Observe that the pages open in a new window, not a new tab. You can set Internet Explorer to open pop-ups in a new window:Īfter doing that, try running window.open(url) and window.open(url, '_blank'). On Internet Explorer (11), for example, users can choose to open popups in a new window or a new tab, you cannot force Internet Explorer 11 to open popups in a certain way through window.open, as alluded to in Quentin's answer.Īs for Firefox (29), the behavior for window.open(url, '_blank') depends on the browser's tab preferences, though you can still force it to open URLs in a popup window by specifying a width and height (see the "Chrome" section below).

new tab redirect

window.open doesn't reliably open pop-ups on a new tab across browsers, and it also depends on the user's preferences. You cannot expect the behavior to be the same across all browsers. Browsers have different behaviors for how they handle window.open






New tab redirect