window.open with target '_blank' opens a new browser window
15,239
try this
onclick="window.open('http://www.google.com', '_self');
Author by
nrsharma
Working as a Software developer in one of the IT Company which delivers the reliable solutions to clients.
Updated on June 04, 2022Comments
-
nrsharma almost 2 years
I am trying to open an link in new browser tab (not in new window).
When I place an link on page like
<a href="#" onclick="window.open('http://www.google.com', '_blank');"> Click Here</a>
when user click on link it will open google in new browser tab. That's fine
BUT
$.ajax({ type: "POST", url: someURL, data: {somedata}, contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { window.open('http://www.google.com', '_blank'); // it's always open in new browser window and I want a new tab }, failure: function (response) { alert(response); return; } });
When I try this within an AJAX web method, it always opens it in new browser window; but I want to open it in new tab as it's working for above example.
I understand this is browser specific functionality but somehow I need to accomplish this.
-
Anoop Joshi P almost 10 yearswhich browser you are using?
-
nrsharma almost 10 yearsMostly Chrome, but our users may be using, IE 9+, FireFox, Safari...
-
Just code almost 10 years
var newWindow = window.open("","_blank");
declare this out of that function and then at the after success of ajaxnewWindow.location.href = newURL
try that if succeed i want to post it as answer ;) -
Dávid Szabó almost 10 yearspossible duplicate of Open a URL in a new tab using JavaScript
-
nrsharma almost 10 years@Justcode, it's same as in new window ...
-
Just code almost 10 yearsbut have u tried i was having the same issue
-
nrsharma almost 10 yearsYes I tried the same you posted in comment above..
-
nrsharma almost 10 years@downvoter I googled alot for it but didn't found any answer. So How can this question have an answer elsewhere.
-
Abdul over 6 yearsadd href="javascript:void(0);" on "a" tag + @Justcode answer works like charm
-
Just code over 6 years@jalil glad it helps
-
-
A.T. almost 10 yearson which browser you are using