title: after browser window close run logout function using javascript or Vuejs
body: <p>Does anyone know anyway that I can use javascript or Vuejs to check when the browser window is close and call logout function? I try this code but when I reload page this function also runs.</p>
  <p>I write this code in the default layout.</p>
  <pre><code>created() {
   window.addEventListener('beforeunload', function (event) {
         console.log(performance.navigation.type,&quot;performance.navigation.type&quot;);
           this.userLogout(); // User Logout Function
          // Cancel the event as stated by the standard.
          event.preventDefault();
          // Chrome requires returnValue to be set.
          event.returnValue = &quot;&quot;;
          (event || window.event).returnValue = null;
          return null;
      }, false);
  }
  </code></pre>