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>?

3
  • This may be relevant: stackoverflow.com/questions/4907843/… Commented Apr 28, 2013 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. Commented Apr 28, 2013 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. Commented Apr 28, 2013 at 18:48

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

0

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

Comments

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"); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.