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
});
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
});
Share
Improve this question
edited Apr 5, 2012 at 8:32
powerbuoy
12.8k9 gold badges51 silver badges83 bronze badges
asked Apr 5, 2012 at 7:42
15091509
751 gold badge2 silver badges15 bronze badges
7
- What code are you using now? Same question: stackoverflow./questions/427479/… – powerbuoy Commented Apr 5, 2012 at 7:43
- $.ajax({ type: "POST", url: "btnTestProject", data: "{'preview':'" + inventory + "' }", contentType: "application/json; charset=utf-8", datatype: "json", cache: false, success: function (response) {window.open(url)}}); – 1509 Commented Apr 5, 2012 at 7:45
- No I meant what code are you using to open the window. The ajax-code is pretty irrelevant. – powerbuoy Commented Apr 5, 2012 at 7:45
- i am using jquery with c# in asp – 1509 Commented Apr 5, 2012 at 7:47
-
Are you using
window.open
or something else to open the new window? Regardless, the answer's in the other question. It's not up to you but the user of the browser. – powerbuoy Commented Apr 5, 2012 at 7:47
3 Answers
Reset to default 2In 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 pletely then you will be having an option in future:
http://www.w3/TR/2004/WD-css3-hyperlinks-20040224/#target-new
You can use this:
#anchorId { target-new: tab ! important }
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.
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>