Skip to content Skip to sidebar Skip to footer

Window.open With Target '_blank' Opens A New Browser Window

I am trying to open an link in new browser tab (not in new window). When I place an link on page like C

Solution 1:

Solution 2:

Solution 3:

You have to play a little trick here. You have to create a hidden a link tag with target='_blank' and set the href of this link tag on ajax success and then trigger the click of this link tag for eg.

HTML code

<a href="#"id="hidden_link" target="_blank">hidden</a>

Js code

$.ajax({
  type: "POST",
  url: someURL,
  data: {somedata},
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function (response) {
   var hiddenLink = $("hidden_link");
   hiddenLink.attr("href",response.href);
   hiddenLink[0].click();  
  },
  failure: function (response) {
    alert(response);
    return;
  }
 }); 

Here is the working fiddle for above code

Post a Comment for "Window.open With Target '_blank' Opens A New Browser Window"