【问题标题】:Recognize browser close in wicket在检票口中识别浏览器关闭
【发布时间】:2020-11-06 15:25:47
【问题描述】:

是否有可靠的方法来检测检票口应用程序中服务器端浏览器选项卡或窗口的关闭情况? 它必须在 firefox 68.11.0 或更高版本下工作。我使用检票口 8.8.0。

我尝试使用 websockets 并捕获连接关闭事件。但不幸的是,刷新页面时也会引发此事件 (F5)。

new WebSocketBehavior() {
    @Override
    protected void onClose(ClosedMessage message) { // invoked on tab close, window close and unfortunately on page reload
        super.onClose(message);
        log.info("Connection for page = '{}' closed.", message.getKey());
    }
}

【问题讨论】:

    标签: wicket


    【解决方案1】:

    从浏览器的角度来看,closing the tabrefreshing the tab 之间没有区别。在这两种情况下,浏览器都会触发 beforeunload JavaScript 事件并关闭所有打开的连接(WebSocket、ServerSideEvent、Ajax)。

    所以,你可以使用

    page.add(new AjaxEventBehavior("beforeunload") {
       @Override public void onEvent(AjaxRequestTarget target) {...}
    });
    

    但这只是告诉您用户导航离开了当前页面。没有信息接下来会发生什么。

    【讨论】:

      猜你喜欢
      • 2010-10-08
      • 1970-01-01
      • 2013-07-24
      • 2010-10-22
      • 1970-01-01
      • 2013-05-12
      • 2014-10-14
      相关资源
      最近更新 更多