Click here to Skip to main content
15,885,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello
I am working an application where each time the user open the page atomatically genrate an id for that page using the database.
All data is stored with that id when the user click save button (the saving button in a server side ) . But how I can do that, If the user click the go back or close buttons in the brower I want a window appear with some text like "You forget to click save button to save your work , If you leave you will lose your work!". In the same time I want to delete the id if the user did not click save button and leave the page.

What I have tried:

I tried to use
window.history.back(1);
in javascript but it doesn't work .
Posted
Comments
F-ES Sitecore 8-Dec-17 5:32am    
What happens if the user just leaves their browser open for a few days rather than closing it?

The internet is stateless so your server code doesn't know if the user is there or not, and no specific events are raised for going back or closing the browser. Basically you can't achieve any of the things you want to do, it's not a desktop application. Instead you need to re-work your site to not care if the user is there or not and to use some other mechanism to know if data should be deleted such as if a certain amount of time has passed since the user accessed any of your pages, or to just delete the data once it is a few days old.
Member 13427929 8-Dec-17 5:42am    
So that not possible ??
F-ES Sitecore 8-Dec-17 5:48am    
No. Websites that do this tend to simply clean up old data after a given time.
Member 13427929 8-Dec-17 5:51am    
Actually I tried something but it doesn't work properly in all browsers .
window.onbeforeunload = function () { return "Your work will be lost."; };
F-ES Sitecore 8-Dec-17 5:54am    
The problem with that event is that it fires even when users move from one page to the next by clicking on links.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900