2012-09-27 65 views
-1

我有一个奇怪的查询,我想打开一个新的窗口(弹出),当浏览器/选项卡关闭使用asp.net,jquery,但我想绕过弹出式窗口阻止程序阻止窗口,任何人都可以帮助我,当用户关闭浏览器/选项卡或任何其他可以帮助我实现的选项时,我如何打开弹出窗口。主要问题是我想忽略弹出式窗口拦截器。在一个SO Post打开弹出窗口从网站没有弹出窗口拦截器捕获它

我读了下面的例子可以帮助:

jQuery(function($) { 
    // This version does work, because the window.open is 
    // during the event processing. But it uses a synchronous 
    // ajax call, locking up the browser UI while the call is 
    // in progress. 
    $("#theButton").click(function(e) { 
    e.preventDefault(); 
    $.ajax({ 
     url:  "http://jsbin.com/uriyip", 
     async: false, 
     dataType: "json", 
     success: function() { 
     window.open("http://jsbin.com/ubiqev"); 
     } 
    }); 
    }); 
}); 

我更换了click事件与$(window).unload,但同样didnt帮助。弹出窗口不会打开,但当我删除e.preventDefault();时弹出窗口打开,但需要启用弹出窗口阻止程序。

+1

在这些情况下,您不能“跳过”弹出式窗口拦截器,因为它是为了阻止这种确切的事情发生而创建的。 – Archer

+0

我怎样才能进入诺克斯堡?里面有一些漂亮的黄金,但是他们把那些讨厌的卫兵放在那里。 –

+0

@Archer错误,OP使用同步AJAX,所以这是可能的。 –

回答

3

我不认为有办法绕过弹出窗口阻止程序。

您应该更改方法并尝试打开jQuery UI modal dialog box中的内容,而不是使用实际的浏览器窗口弹出窗口。

+0

好,按照与jQuery的UI模式对话框,我可以打开模式对话框关闭浏览器/选项卡。 – Abbas

+1

jQuery的模态对话框是模拟弹出窗口的HTML模拟,因此它必须位于页面内。您可以在窗口关闭之前打开它 –

+0

您可以帮助我如何在关闭窗口之前打开模式弹出窗口,我使用的是onbeforeunload,但这里的问题是当我关闭窗口时,它首先显示警告消息,并且如果用户点击停留在页面上,只有该模式可见,并且页面加载时也会显示留言消息框 – Abbas

0

弹出式窗口拦截器旨在防止此行为。

我会建议使用模态窗口而不是实际的浏览器窗口。我不认为这些被封锁,因为它们是在页面内部打开的。

至于事件...你可以做这样的事情......

window.onbeforeunload = function whatever() { 
     //Do code here for your modal to show up. 
} 

如果你只是想OT给予警告或东西,你可以做

window.onbeforeunload = function showWarning() { 
     return 'This is my warning to show'; 
} 
1

你必须在与$.ajax相同的功能中打开窗口,否则某些浏览器仍会拒绝弹出窗口。

jQuery(function($) { 
    // This version does work, because the window.open is 
    // during the event processing. But it uses a synchronous 
    // ajax call, locking up the browser UI while the call is 
    // in progress. 
    $("#theButton").click(function(e) { 
    // use success flag 
    var success = false; 
    e.preventDefault(); 
    $.ajax({ 
     url:  "http://jsbin.com/uriyip", 
     async: false, 
     dataType: "json", 
     success: function() { 
      success = true; // set flag to true 
     } 
    }); 
    if (success) { // and read the flag here 
     window.open("http://jsbin.com/ubiqev"); 
    } 
    }); 
}); 

这是为了确保uriyip被调用时,它的完成加载弹出一个窗口,唯一可靠的方法;所以它冻结了浏览器,太糟糕了。