[SOLVED] What happens when user leaves the web page at the same tab of browser?

Answered
0
0

I made a simple app that shows a MessageBox when a button is clicked.

After that Messagebox is shown, I navigate to another website at the same tab of browser , so if I click in the back button of browser the App reloads and show the same Messagebox waiting to be clicked, this means that Wisej app has stored this state and is consuming memory at the server even if I leave the page.

Is there a way to force Wisej app to exit when user leaves the web page and show a message to user that he is to loose data if leave the page?

  • You must to post comments
Best Answer
0
0

Hi Joe,

it is not possible for Wisej and also for any other application which runs in a browser to determine when user closes the browser.

One way to show up a warning, when the user tries to leave the page is described here.

The problem in this solution is, that the unload event is also fired when the user refreshes the browser. And on server you cannot distinguish if the browser was closed or the user just hit F5.

But you can add for example a button to your app which will call Appliaction.Exit(), this will terminate the application and the corresponding session.

When the user leaves the page or closes the browser, Wisej will also terminate the App and the session after twice of SessionTimeout. SessionTimeout you can configure in Default.json.

Best,

Jens

  • Jeo dg
    You said: “When the user leaves the page or closes the browser, Wisej will also terminate the App…” This is not what happens, Wisej does not terminate the app when I leave the page. As I said, If I go to another website at the same tab of browser and return back, the app reloads and shows the same state,
  • Luca (ITG)
    Jens wrote the opposite of what you wrote. He is correct, it is impossible for any browser and any web application to determine when the browser is closed, or a tab is closed or a navigation occurs, or the url is changed. It’s this way since the beginning of dynamic web pages. From php, to jsp, asp, cgi, etc there is the session timeout concept. There is a lot of information around about this basic topic.
  • Jeo dg
    I’m sorry, I guess I didn’t explain my point. What I mean is: WiseJ DOES NOT CLOSE the application when the user leaves the page. Example: test it by showing a Messagebox and exiting the page by typing a URL and returning to the application again by clicking the “Go Back” button of browser, you will see that the application will be RELOADED and MessageBox will be there again, with the SAME state.
  • Luca (ITG)
    That is correct and the intended behavior. The session will be removed when it expires. If you want to terminate the session when the user navigates away, or hits F5, or hits refresh, or edits the URL (they are all the same for the browser) let me know. I can send you a simple example that does that.
  • jin tom
    Is possible to using Redis as session storage ?
  • You must to post comments
0
0

Add this to Default.html. It will abandon the session when navigating, closing the tab, refreshing, hitting F5, or editing the URL. The alert behavior is different for different browser and some may or may not show the alert when refreshing. I think this is the wrong thing to do for a web application, but in Wisej you can do anything you’d like to do using standard browser functionality…

 <script>
   window.addEventListener("beforeunload", function (e) {
     e.preventDefault();
     e.returnValue = false;
     return "Are you sure?"; // this shows only in IE.
   });
   window.addEventListener("unload", function (e) {
    Wisej.Core.exit();
    Wisej.Core.removeSession();
   });
 </script>

 

  • jesus morales
    I have the indicated script implemented in Default.html and it worked correctly until I updated to version 2.2. Now closing the browser tab does not close the session to the server. Is it necessary to make any changes to the script or some other solution for this problem?
  • You must to post comments
0
0

Thank you Nic Adams, I’m sorry, that’s not what I want to know. I reformulated my question, please, could you answer again?

  • You must to post comments
0
0

Hi Jeo,

If you mean what happens when a user closes their browser then eventually you should get the Application.Exit event fire if you want to do something specific, otherwise you can leave it to WiseJ to clean up the users session.

HTH

Nic

 

 

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.