如何检测浏览器是否启用弹窗拦截器(Vaadin框架场景)
关于Vaadin中检测浏览器弹窗拦截器的问题
- 无法检测浏览器是否启用弹窗拦截器,测试过的Vaadin版本包括14.2.0、14.3.0、14.4.0、14.9.6,在Vaadin V24中也未找到相关配置项。
- 尝试寻找解决方案时,曾得到使用
PopupBlockerDetector类的建议,但该类实际并不存在。 - 已尝试以下两段示例代码:
示例1:打开外部弹窗检测
String popupUrl = "https://www.example.com/popup"; String windowName = "popup"; int width = 800; int height = 600; String features = String.format("width=%d,height=%d", width, height); Window window = UI.getCurrent().getPage().open(popupUrl, windowName, features); if (window == null || window.closed || !window.isResizable()) { // popup was blocked or closed by the user Notification.show("Popup is blocked!"); }
示例2:使用Dialog检测
Dialog dialog = new Dialog(); dialog.add(new Span("Test span")); UI.getCurrent().add(dialog); Notification.show(MessageFormat.format("Dialog is opened? {0}", dialog.isOpened()));
- 问题仅出现在Safari、Firefox浏览器中。
内容的提问来源于stack exchange,提问作者Franco Rolando
相关产品推荐
相关产品推荐

