1

How does one go about opening a new tab with no URL in the address bar via an onClick event from a webpage as if you clicked on the "+" button to the right of all the tabs.

Yes, I can do onClick={() => window.open('', '_blank')} to open a new tab without a URL. But that will result in about:blank appearing in the address bar. Something I don't want. The new tab that opens should be exactly as if you clicked on the "+" button.

JFYI, I'll also be okay if instead of a new tab opening, the page where the onClick originated from becomes the blank page. As if you clicked the home button.

Mix Master Mike
  • 1,079
  • 17
  • 26
  • on chrome is `chrome://newtab` , on other browsers i don't know if it's possible – ariel Apr 24 '20 at 03:47
  • How do you implement `chrome://newtab`? I did the following, `onClick={() => window.open('https://www.google.com/_/chrome/newtab', '_blank')}`. While it did open a new tab, the address bar was not blank. – Mix Master Mike Apr 24 '20 at 03:57
  • `window.open('chrome://newtab', '_blank')` Check the user agent before – ariel Apr 24 '20 at 04:03
  • 1
    I just found another SO question just like mine from 3 years ago with no concrete answer. https://stackoverflow.com/questions/37596150/how-do-i-open-the-new-tab-page-explicitly-in-chrome-from-a-web-page – Mix Master Mike Apr 24 '20 at 04:03
  • 1
    Gotcha. I'll give that a try. I have no idea what the user agent is but let me do some reading. As of now, when I execute `window.open('chrome://newtab', '_blank')` I see the following error in my console, `Not allowed to load local resource: chrome://newtab/`. Does this have something to do with the user agent? Don't know but I'll investigate. – Mix Master Mike Apr 24 '20 at 04:09
  • Ah.. then it won't work, sorry, haven't tested. Guess you're stuck with `about:blank` then :( – ariel Apr 24 '20 at 04:13
  • Dang. I really don't want to give up this easily. I'll look into this a bit more. – Mix Master Mike Apr 24 '20 at 04:16
  • Does this answer your question? [Open a URL in a new tab (and not a new window)](https://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window) – fIwJlxSzApHEZIl Jun 18 '20 at 17:24
  • I am also trying to do this, but from a Chrome extension popup in order to open my custom new tab. It's possible with the `tabs` permission and `chrome.tabs.create(...)`, but this causes my users to think I'm "reading all browser history" because of the permission scope. – user Aug 03 '20 at 10:39

3 Answers3

1

Unfortunately there isn't a way to do what you want using available browser APIs. The syntax of window.open is window.open(URL, name, specs, replace). The first 2 is what defines how this new "window" is opened. The url of where the window should go. This can be left as an empty string, but will open a window as "about:blank". The 2nd part is the name, which defines how the window should be open (tab, window, etc).

Local resources can't be loaded with this URL, so "chrome://newtab" won't work. Trying to use a period as your url will open the new window with whatever page the window was opened from. Trying to use a slash as the url will open the new window as the base path of where the new window was created from. Invalid urls that I tried (random strings and characters) will just open a new window with your current url, but also append whatever you typed.

From what it looks like, you're stuck with "about:blank", or having to look in to other options.

Sources for reference

hedy
  • 1,160
  • 5
  • 23
Chris
  • 1,484
  • 1
  • 12
  • 19
0

about:newtab seems to work in chrome and Firefox but not in edge. While about:home works in Firefox and edge but not chrome. You could probably detect the web browser and act accordingly.

Update:

Sorry, these pages appear to be privileged and cannot be acceded by other websites.

Geo
  • 543
  • 5
  • 16
-5

could you use any of these

<a href="javascript:if(navigator.appName.indexOf('Microsoft Internet Explorer') != -1){location='http://facebook.com/';}if(navigator.appName.indexOf('Netscape') != -1){
window.open('http://facebook.com/','','width=600,height=400,left=50,top=50,toolbar=yes');};void 0">
New new window</a>

<input type="button" value="
New new window" onclick="javascript:window.open('http://facebook.com/','','width=600,height=400,left=50,top=50,toolbar=yes');" />
AN German
  • 725
  • 10
  • 10