我在网上有一个使用JS Alerts的小应用程序。我打算以后再使用模式弹出窗口,但是暂时没有人知道如何检测用户是否单击了“防止创建其他对话框阻止此页面”,然后触发了一些js函数?
最佳答案
确实有可能通过使用javascript日期来检测是否阻止了其他对话框的单击
您可以尝试以下代码行
window.nativeAlert = window.alert;
window.alert = function(message) {
var timeBeforeAlert = new Date();
var confirmIfBlocked = nativeAlert(message);
var timeAfterAlert = new Date();
if ((timeAfterAlert - timeBeforeAlert) < 400) {
tellTheUserDialog("you can use a Div to tell the user he has blocked alert");
}
}
如果用户没有看到警报,那么timeAfterAlert将与timeBeforeAlert几乎相同,我用了400毫秒作为参考,您可以提出自己的建议