使用JavaScript测试弹出窗口阻止程序

Popup Window

Several websites rely on the ever-so-annoying popup window. As much as well all hate popup windows, some websites do benefit and justly require them. The problem is that some people have their popup blocker on but don't know it -- thus the new window doesn't open. Of course the browser notifies the user but it isn't always as obvious as it should be. Here's a quick method for testing if your popup window is being blocked.

一些网站依赖于如此烦人的弹出窗口。 就像所有讨厌的弹出窗口一样,有些网站确实受益并公平地需要它们。 问题是有些人打开了弹出窗口阻止程序,但不知道该阻止程序-因此不会打开新窗口。 当然,浏览器会通知用户,但并不总是那么明显。 这是一种测试弹出窗口是否被阻止的快速方法。

JavaScript (The JavaScript)


var windowName = 'userConsole'; 
var popUp = window.open('/popup-page.php', 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 click the "Open" link again.'); 
} 
else { 	
	popUp.focus();
}


The first step is to give the directive to open a new window, saving what's returned. Then we check to see if the object exists. If it does, we're good. If it doesn't, we give an alert to the user that their popup blocker may be on. The specific text warning can be set to whatever you'd like, as could the method of giving them the message. You could also use a sexy MooTools slider to show the message.

第一步是给指令打开一个新窗口,保存返回的内容。 然后我们检查对象是否存在。 如果可以,那么我们很好。 如果不是,我们会向用户发出警报,告知他们的弹出窗口阻止程序可能已启用。 可以将特定的文本警告设置为您想要的任何内容,也可以将其设置为向他们发送消息的方法。 您也可以使用性感的MooTools滑块显示消息。

翻译自: https://davidwalsh.name/popup-block-javascript

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值