function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DIVYANSHU BHUSHANDIVYANSHU BHUSHAN 

How I show a warning message on click of Close[X]?

I need to show a warning message, when user click on the close[X] on right upper corner of the window, in a visualforce page. Any suggestiion is much appreciated.
Best Answer chosen by DIVYANSHU BHUSHAN
Swayam@SalesforceGuySwayam@SalesforceGuy
Hey Bhushan,

You Can Use Below JavaScript in your Visualforce Page 

This script will show warning whenever you are moving from the vf page, you can add filter condition if you want it only for close

Code Below :
 
<script>
window.onbeforeunload = function(e) {
    return ' Your Desired Waring on Page Close.';
};
</script>

--
Regards,
Swayam @Salesforceguy




 

All Answers

Swayam@SalesforceGuySwayam@SalesforceGuy
Hey Bhushan,

You Can Use Below JavaScript in your Visualforce Page 

This script will show warning whenever you are moving from the vf page, you can add filter condition if you want it only for close

Code Below :
 
<script>
window.onbeforeunload = function(e) {
    return ' Your Desired Waring on Page Close.';
};
</script>

--
Regards,
Swayam @Salesforceguy




 
This was selected as the best answer
Swayam@SalesforceGuySwayam@SalesforceGuy
Hey,

 If it works don't forget to mark it as a best answer.

--
Regards,
Swayam
@Salesforceguy