窗口/选项卡未激活时弹出警报
我在这里尝试了很长一段时间但没有运气。
您知道如何在用户从浏览器中更改选项卡/窗口时显示弹出(警报)吗?
所以基本上,当用户在他/她的浏览器上更改窗口时,警报窗口将会弹出,用户必须按“确定”按钮才能继续,
因为我正在创建一个在线测试站点并且需要显示每当用户尝试更改选项卡/窗口时发出警报
I am trying for quite some time here but with no luck.
Do you have any idea how you can make a pop-up (alert) show, whenever the user changes tab/window from his browser?
So basically, when the user changes a window at his/her browser, the alert window will pop and the user will have to press the ok button to continue
This funcitonality is needed as I am creating an online tests site and I need to display the alert whenever the users will try to change tab/window
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在窗口对象上使用
focus
和blur
事件(选项卡也被视为窗口。)尝试一下:或使用 jQuery:
另外,请小心使用警报以这种方式。许多用户可能会觉得有点烦人。
You can use the
focus
andblur
events on the window object (tabs are considered windows, too.) Try this out:or with jQuery:
Also, be careful about using alerts in this manner. Many users may find it a bit annoying.