You need to sign in to do that
Don't have an account?

Executing some code when leaving a VF page
Hello
I need some expert advice...
I want to have some code to be executed once the user leaves a VF page.
My case is that I want to save some changes the user makes to the page only when the user leaves the page to avoid multiple database calls.
Is there any way I can do that?
Thanks
Oded
add this script to your vfp, in this I have used window.onbeforeunload event
this will show an alert every time user leave the page but you just need to call an actionFunction to save the data instead of alert. Let me know if any issues in it.
All Answers
Do you count browser actions like closing the window or navigating forward or backwards using browser as well the case of leaving the page and do you want to save info in that case as well.
Yes, I want to make the DB call only when the user closes, navigates back or forward or leaves the page
Do you have any idea what should I do?
Thanks
Oded
add this script to your vfp, in this I have used window.onbeforeunload event
this will show an alert every time user leave the page but you just need to call an actionFunction to save the data instead of alert. Let me know if any issues in it.
Thank you very much
Your Welcome Mate