1

I need to open a new link automatically inside

if(isset($_POST['download'])) {
...
}

after user clicks on submit button download.

I tried document.location, but it opens a link in the same tab, and window.open requires that the browser should have pop-ups enabled, which can be annoying to users, plus in Chrome (may be also in some other browsers), target="_blank" opens a link in new window, not in a new tab.

Is there anything I can use to open a window normally in a new tab, like with <a href=""></a>?

Vivek Jain
  • 3,811
  • 6
  • 30
  • 47
user2328948
  • 19
  • 2
  • 4
  • This may be relevant: http://stackoverflow.com/questions/4907843/open-url-in-new-tab-using-javascript – RandomDuck.NET Apr 28 '13 at 18:14
  • 5
    You can't control whether a window will open in a new tab or in a window, that's completely up to the browser. – Marcel Korpel Apr 28 '13 at 18:19
  • @MarcelKorpel I agree, but more specifically it's up to the user - I'm quite sure most common browsers have a user-changeable setting specifying whether new windows open in tabs or windows. The browser does have a default, but you can't accurately say window vs tab based solely on the browser. Additionally, right-click -> Open in Tab/Window will override even that setting. – DACrosby Apr 28 '13 at 18:48

4 Answers4

1

All modern browser now contain tab functionality.

Try window.open(), browser will automatically will do task as per its configuration.Different browser treat target="_blank" differently.Mozilla open in new tab while chrome not.It is not up to you.

Notepad
  • 1,659
  • 1
  • 12
  • 14
0

You cannot ensure they will open it in a new window, but you can make an effort at it.

For example:

<a href="go/Where-ever" target="_blank">Link Text</a>

Like you said, you can do this with JavaScript

var anchors = document.getElementsByTagName('a'); // or another selector

for ( var i in anchors ) 
    anchors[i].onclick = function () { return !window.open(this); };

Inline JavaScript

<a href="go/Where-ever" onclick="window.open(this.href);return false;">Link Text</a>

And jQuery

$(".linkSelector a").prop("target","_blank");

But remember, browser settings, Right-Click->Open in New Tab, and Right-Click->Open in New Window can override all of this. But that's not really a bad thing generally - most people like windows opening as tabs/windows and they get irritated at, or don't pay attention to anything that ignores their wishes.

DACrosby
  • 11,116
  • 3
  • 39
  • 51
0

window.open() is used to do the taskyou can see the example here

0

The below code will help you to open the page at new window.

 window.open("https://stackoverflow.com", "_blank","toolbar=yes,top=200,left=200,width=800,height=800");
Kushal
  • 2,605
  • 4
  • 22
  • 23