JEYASHRI R
JEYASHRI R

Reputation: 452

JavaScript open in a new tab, not window in Chrome browser

I am using,

window.open("Download.php");

This file opens in a new tab for all browsers. But in Chrome, it opens in a new window. So I have tried:

window.open("Download.php",'_blank'); 
window.open("Download.php",'_new');

But it still opens in new window, not a tab. I don't know if this is a coding problem or default settings problem. I am using Chrome v31.0.1650.57 m.

Upvotes: 3

Views: 11444

Answers (2)

The Spooniest
The Spooniest

Reputation: 2873

Short answer: you can't. At least for now, the browser vendors view this as something that should strictly be left to users to define for themselves. You set your target to something that should be a new window, and the browser will use the user's preferences to decide whether it opens as a new window or a new tab.

Long answer: There's a CSS property that would do this on the HTML side, but none of the browsers support it. According to the proposal, you'd use target-new: tab for links that you explicitly want to open in a new tab, and target-new: window for those you want to open in a new window. I don't know of any DOM proposals to do something analogous to this on the JavaScript side.

Upvotes: 1

Zaheer Ahmed
Zaheer Ahmed

Reputation: 28528

You can try:

var tab=window.open("Download.php",'_blank'); 
tab.focus();

Steps to verify

create a html file with markup:

<html>
 <body>
   <script>
     function newTab(){
        var tab=window.open("http://conceptf1.blogspot.com/2013/11/javascript-closures.html",'_blank'); 
        tab.focus();
     }
   </script>
   <a href="#" onclick="newTab()">Open Tab</a>
  </body>
</html>

Open it in chrome and click the link.

Upvotes: 1

Related Questions