简体   繁体   中英

Browser tab close detect in gwt

I am developing a gwt application and I am going to support only for ie7. Now I have a requirement to detect browser tab close event.I have tried Window.addWindowClosingHandler(...) . But this is getting fired when we click any url in the page or refresh. I just want to detect only browser close event. I dont want to capture any other event like browser refresh, url click. 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(); 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.

The underlying JavaScript event is the onbeforeunload event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM