8/9/2023 0 Comments 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. 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. 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. 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. 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). 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. The highlighting broke in Chrome 34 and appears to be broken now in Chrome 61 (a bug I just reported).Browsers have different behaviors for how they handle window.open However, this appears to be undocumented and unreliable. Using to redirect the new tab page has historically highlighted the URL.There's an ongoing, unsolved thread on this topic here for the Chrome extension New Tab Redirect.The ideal solution would keep the webpage be the top frame of the new tab page, and the omnibox would be either cleared or highlighted. However, this does not reliably highlight the omnibox, so users have to manually set focus to the omnibox before typing, which is a poor user experience. Redirect the local new tab page to the webpage.However, many websites won't work properly when iframed. iframe the webpage in the local extension page.The chrome_url_overrides.newtab option in the extension manifest only allows local HTML pages. Is there a clean way for a Google Chrome extension to set a non-local webpage as the new tab page while also keeping the omnibox cleared or highlighted?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |