1509
1509

Reputation: 75

Open a new link in new tab in chrome

I am trying to open a link in a new tab on ajax success, but the link opens in a new window. How to forcefully open the link in a tab rather than in a new window in chrome with jquery or javascript.

Code:

$("#A1").click(function (event) {
    $.ajax({ 
        type: "POST", 
        url: "Home.aspx/btnTestProject", 
        data: "{'preview':'" + inventory + "' }", 
        contentType: "application/json; charset=utf-8", 
        datatype: "json", 
        cache: false, 
        success: function (response) { 
            window.open("TestnRun.aspx"); //opens in new window 
        }    
    }); 

    window.open("TestnRun.aspx"); //opens in new tab 
});

Upvotes: 2

Views: 10685

Answers (3)

Davide Dolla
Davide Dolla

Reputation: 350

I saw the same thing.

And I've noted that (I'm using jquery.1.9.1):

if you call $.ajax in async, or % the browser (Chrome) open in NEW WINDOW, else if you run a JSON call SYNC the window will be open tabbed!

This open in a NEW WINDOW, pop-up:

  $.ajax({ url: "/cliFindExist/", 
    async: true, 
    function(data){... 
    window.open("some.aspx","_blank")});

This open window TABBED

$.ajax({ url: "/cliFindExist/", 
async: false, // <<<<<<<<<<<<< NOTE
function(data){... 
window.open("some.aspx","_blank")});

JQuery may be change the way/context when it call the function? depending if it run a sync or an async call.

Upvotes: 2

ZeNo
ZeNo

Reputation: 1658

In general you cannot control it. As this is user preference to open link with target="_blank" in new window or tab.

When browsers starts supporting css-3 completely then you will be having an option in future:

http://www.w3.org/TR/2004/WD-css3-hyperlinks-20040224/#target-new

You can use this:

#anchorId { target-new: tab ! important }

Upvotes: 2

dash1e
dash1e

Reputation: 7807

Use target "_blank" like this

<a href="http://www.google.it" target="_blank">My link</a>

or with Javascript like this

<button onclick="window.open('http://www.google.it','_blank')">Button</button>

Upvotes: 1

Related Questions