Programmatically open new pages on Tabs
I’m trying to “force” Safari or IE7 to open a new page using a new tab.
Programmatically I mean something like:
You can’t directly control this, because it’s an option controlled by Internet Explorer users.
Opening pages using Window.open with a different window name will open in a new browser window like a popup, OR open in a new tab, if the user configured the browser to do so.
You can, in Firefox it works, add the attribute target=”_newtab” to the anchor to force the opening of a new tab.
<a href="some url" target="_newtab">content of the anchor</a>
Said that, I partially agree with Sam. You shouldn’t force user to open new pages or new tab without showing them a hint on what is going to happen before they click on the link.
Let me know if it works on other browser too (I don’t have a chance to try it on other browser than Firefox at the moment).
Edit: added reference for ie7
Maybe this link can be useful
Those of you trying to use the following:
should really look at the window.open method.
All you are doing is telling the browser to open a new window NAMED “_newtab” and load page.html into it. Every new page you load will load into that window. However, if a user has their browser set to open new pages in new tabs instead of new windows, it will open a tab. Regardless, it’s using the same name for the window or tab.
If you want different pages to open in different windows or tabs you will have to change the NAME of the new window/tab to something different such as:
Of course the name for the new window/tab could be any name like page1, page2, page3, etc. instead of _newtab2.
It’s up to the user whether they want to use new tabs or new windows, it isn’t the business of the developer to modify this behaviour. I do not think you can do it.
Have you already tried like
var open_link = window.open('','_blank'); open_link.location="somepage.html";
I found out in Chrome,
will only work once.
You can use:
window.open(ct.getNewHref(),'_newtab' + Math.floor(Math.random()*999999));
To open multiple new tabs.