[英]Browser tab close detect in gwt
I am developing a gwt application and I am going to support only for ie7. 我正在开发gwt应用程序,并且仅支持ie7。 Now I have a requirement to detect browser tab close event.I have tried Window.addWindowClosingHandler(...) .
现在我需要检测浏览器选项卡关闭事件。我尝试了Window.addWindowClosingHandler(...)。 But this is getting fired when we click any url in the page or refresh.
但是,当我们单击页面中的任何URL或刷新时,就会触发这种情况。 I just want to detect only browser close event.
我只想检测仅浏览器关闭事件。 I dont want to capture any other event like browser refresh, url click.
我不想捕获任何其他事件,例如浏览器刷新,URL单击。 Is there any way to detect only that.
有什么方法可以检测到这一点。
it should work 它应该工作
Window.addCloseHandler(new CloseHandler<Window>() {
@Override
public void onClose(CloseEvent<Window> event) {
Window.alert("bye bye beautiful");
}
});
[EDIT] [编辑]
or maybe you search onBrowserEvent();
或者您搜索
onBrowserEvent();
and detect which event user do 并检测用户执行哪个事件
public void onBrowserEvent(Event event)
{
switch (DOM.eventGetType(event))
Event.onClick
Event.onPaste
Event.onLoad
您可以使用会话cookie,如在此问题的选定答案中所述: 也可以在浏览器刷新时触发GWT WindowClosingHandler
JavaScript doesn't expose what caused the page to get closed, so GWT unfortunately cannot expose this information. JavaScript不会公开导致页面关闭的原因,因此GWT不幸地无法公开此信息。
The underlying JavaScript event is the onbeforeunload event. 底层的JavaScript事件是onbeforeunload事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.