如何避免弹出窗口被阻止?每当我点击按钮时,会弹出通知并说它会像我说的那样被重定向。但Chrome表示它无法打开新标签,因为它已弹出窗口阻止。
$(function () {
$('#clickBtn').on('click', function () {
new Noty({
type: 'success',
layout: 'topRight',
timeout: timeout,
text: '<p style="text-align: center">Redirecting in 5
seconds</p>'
}).show();
var url = 'https://google.com',
delay = 5000; // Milliseconds: 1sec x 1000
setTimeout(function () {
window.open(url, '_blank');
}, delay);
});
答案 0 :(得分:0)
你不能避免弹出窗口拦截器, 但你可以检查是否是浏览器阻止弹出窗口..
var windowName = 'userConsole';
var popUp = window.open('htttp://www.google.com', windowName, 'width=1000, height=700, left=24, top=24, scrollbars, resizable');
if (popUp == null || typeof(popUp)=='undefined') {
alert('Please disable your pop-up blocker and try again.');
}
else {
popUp.focus();
}