Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Differentiating browser tab close and <code>refresh</code> functionality is really a pain because we don't have two events to know which event being fired.</p> <p>But there are always some requirements :)</p> <p>What I'm doing is setting one <code>cookie</code> in on-load and making a flag true if found that <code>cookie</code> and removing the cookie on browser close event.</p> <p>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.</p> <p>Note:Solution provided with help of <code>Cookies.</code></p> <p>In Here is the onModule() for GWT / same as <code>onload/document.ready()</code> for <code>java script/Jquery</code>.</p> <pre><code> @Override public void onModuleLoad() { if("already_in_browser". equalsIgnoreCase(Cookies.getCookie("already_in_browser"))){ showAlreadyTabActiveDialog(); return; }else{ setLoggedincookie(); } private void setLoggedincookie() { isLoggedintab = true; //this is a global variable registerWindowCloseEvent(); com.google.gwt.user.client.Cookies. setCookie("already_in_browser","already_in_browser"); } private void showAlreadyTabActiveDialog() { alert("You are already active in another tab"); registerWindowCloseEvent(); } /** This event is onbeforeunload in javascript private void registerWindowCloseEvent() { Window.addCloseHandler(new CloseHandler&lt;Window&gt;() { @Override public void onClose(CloseEvent&lt;Window&gt; event) { if(isLoggedintab ){ Cookies.removeCookie("already_in_browser"); } } }); } </code></pre> <p>Let me know If you found any bugs or loop holes in this.So that I'l look in to them.</p> <p>I would be very happy,If some one provide a solution,without using <code>cookies</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload