How can Differentiating browser tab close and refresh functionality.
As of now window refresh and close event doesn't have different events.
My requirement is to checking weather user already logged in or not in any of tabs,So that I wont allow him to load my app in any other tabs.
In GWT (java)
private void registerWindowCloseEvent() {
Window.addCloseHandler(new CloseHandler<Window>() {
@Override
public void onClose(CloseEvent<Window> event) {
// do something on close
}
});
}
in JavaScript/Jquery:
window.onbeforeunload = function(e) {
// do something on close
};
The above events are firing for both the events refresh and close..is there any way to differentiate.
Differentiating browser tab close and
refresh
functionality is really a pain because we don't have two events to know which event being fired.But there are always some requirements :)
What I'm doing is setting one
cookie
in on-load and making a flag true if found thatcookie
and removing the cookie on browser close event.So until unless the he closed the active tab(logged in tab), that cookie still there and if he tries to open in another tab, then the already active dialog comes.
Note:Solution provided with help of
Cookies.
In Here is the onModule() for GWT / same as
onload/document.ready()
forjava script/Jquery
.Let me know If you found any bugs or loop holes in this.So that I'l look in to them.
I would be very happy,If some one provide a solution,without using
cookies
.