2013-05-10 17 views
2

我曾嘗試以下,以實現這一目標中打開一個新的瀏覽器標籤:如何從一個jQuery回調

但是從內部呼叫window.open時既不作品回電話。這裏是我的代碼

$.post('api', { 
    }, function() { 
    var win = window.open('target-file', '_blank'); 
    win.focus(); 
    }); 
+2

新窗口可以通過被阻擋的Web瀏覽器的新標籤中打開每個外部鏈接彈出窗口阻止程序? – mariusnn 2013-05-10 10:12:47

+0

可能的重複[爲什麼我不能打開一個新的窗口在我的jquery ajax回調?](http://stackoverflow.com/questions/2791047/why-cant-i-open-a-new-window-on- my-jquery-ajax-callback) – 2013-05-10 10:13:01

回答

1

嘗試與窗口的名稱

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

SEE HERE

+0

感謝您的回覆,但這也不起作用。 – coder9 2013-05-10 10:51:08

0

使用MySurfaceWindow = window.open("url","windowname","settings");
見下面的例子:

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'); 
2

試試這個:

$.post('api', { 
    }, function() { 
    window.open('target-file', '_blank'); 
    }); 
+0

號不起作用。謝謝回覆 – coder9 2013-05-10 10:50:28

0

OU可以在此簡單的jQuery snipplet添加到您的源

$(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'); 
     }); 
    } 
    }); 
}); 
相關問題