2

I have tried the following to achieve this:

But neither works when calling window.open from inside the callback. Here's my code

$.post('api', { 
    }, function() {
    var win = window.open('target-file', '_blank');
    win.focus();
    });
Community
  • 1
  • 1
coder9
  • 1,571
  • 1
  • 27
  • 52
  • 2
    The new window may be blocked by a popup-blocker? – mariusnn May 10 '13 at 10:12
  • possible duplicate of [Why can't I open a new window on my jquery ajax callback?](http://stackoverflow.com/questions/2791047/why-cant-i-open-a-new-window-on-my-jquery-ajax-callback) – Adil Shaikh May 10 '13 at 10:13

4 Answers4

2

Try this:

 $.post('api', { 
    }, function() {
    window.open('target-file', '_blank');
   });
Somnath Kharat
  • 3,570
  • 2
  • 27
  • 51
Sandy
  • 107
  • 13
1

try it with the name of the window

Like

window.open("url", "NameOfNewWindow");

SEE HERE

Community
  • 1
  • 1
PSR
  • 39,804
  • 41
  • 111
  • 151
0

use MySurfaceWindow = window.open("url","windowname","settings");
see below example:

MySurfaceWindow = window.open('/DesktopModules/DMS/DMS.PatientEChart/Surface Pages/Surface6.aspx?SurfaceTooth=' + $("#lbl" + $(this).val()).text() + '&ProcedureID=0' + '&ColorD=I' + '', '', 'height=240,width=200,top=' + top + ',left=' + left + 'status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no');
Somnath Kharat
  • 3,570
  • 2
  • 27
  • 51
0

ou can add this simple jQuery snipplet to your source to open every external link in a new tab of the web browser

$(document).ready(function(){
  $('a').each(function() {
    var a = new RegExp('/' + window.location.host + '/');
    if(!a.test(this.href)) {
      $(this).click(function(event) {
        event.preventDefault();
        event.stopPropagation();
        window.open(this.href, '_blank');
      });
    }
  });
});
David Fawzy
  • 1,056
  • 15
  • 17