Javascript 如何从jQuery回调中打开新的浏览器选项卡
为了实现这一目标,我尝试了以下方法:Javascript 如何从jQuery回调中打开新的浏览器选项卡,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,为了实现这一目标,我尝试了以下方法: 但是在调用窗口时这两种方法都不起作用。请从回调内部打开。这是我的密码 $.post('api', { }, function() { var win = window.open('target-file', '_blank'); win.focus(); }); 用窗口的名称试试看 像 使用MySurfaceWindow=window.open(“url”、“windowname”、“settings”) 请参见以
窗口时这两种方法都不起作用。请从回调内部打开。这是我的密码
$.post('api', {
}, function() {
var win = window.open('target-file', '_blank');
win.focus();
});
用窗口的名称试试看
像
使用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');
试试这个:
$.post('api', {
}, function() {
window.open('target-file', '_blank');
});
您可以将这个简单的jQuery snipplet添加到源代码中,以在web浏览器的新选项卡中打开每个外部链接
$(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');
});
}
});
});
新窗口可能被弹出窗口拦截器阻止?可能重复
$(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');
});
}
});
});