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
shravanshravan 

When closing Salesforce tab to get the alert

Hi,

 

When closing Salesfoce page I have to get the alert like 'do you want close the page' . Like that I have to get the message when I am closing My salesforce Tab.

 

Please Help Me.

Ankit AroraAnkit Arora

On which browser you are working? And when you are facing this error, when you close the tab in which any visualforce page is opened or any tab of salesforce?

 

Also it will be good if you can provide us the screen shots.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

shravanshravan

Hi,

 

when we closing salesfoce page it is closing, we are getting any dailog box. But My requirement is when I am closing salesfoce page I have get the dailog box.

 

 

Please Reply Me

Ankit AroraAnkit Arora

Not sure, but you can do this using JS on your visualforce page on "onClose" event.

 

And if you want that alert on every page then you can do this again by using JS in home page component.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

shravanshravan

Hi,

 

when we closing salesfoce page it is closing, we are not getting any dailog box. But My requirement is when I am closing salesfoce page I have get the dailog box.

 

 

Please Reply Me

Ankit AroraAnkit Arora

Please do not post the same content again and again. If you want to change any text in your post you can click on "Options" and edit your reply.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

shravanshravan

Hi,

 

 

we are implemented but problem is when we clicking Lead, Opp, Acc,.... any button in page we are getting that dialog box.

 

 

 

 

Imran MohammedImran Mohammed

Hi Shravan,

 

Can you be more clear on your requirement?

 

Are you closing a Visualforce tab or Standard SFDC Tab and for which Tab the prompt is shown?

 

Its better if you post the screenshots as Ankit said else will be tough to understand what needs to be done.

 

 

shravanshravan

Hi Imran,

 

Our requirement is to perform an action when a Visual Force page is closed. We are able to achieve a partial solution. We are able to capture the following action using javascript.

  • On clicking the right top close button.

But we are not able to capture the following actions

  • File-->Close Tab/Exit
  • Right click the page from the task bar and close
  • Alt+F4

 

 

 

 

 

HarpreetHarpreet

Hi Shravan,

 

Try pasting the below mentioned code in a Visualforce Page and let me know if it does not work.

 

<script>
function goodbye(e) { if(!e) e = window.event; //e.cancelBubble is supported by IE - this will kill the bubbling process. e.cancelBubble = true; e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog //e.stopPropagation works in Firefox. if (e.stopPropagation) { e.stopPropagation(); e.preventDefault(); } } window.onbeforeunload=goodbye;
</script>

 

Regards,

 

Harpreet Dhillon

Salesforce Developer.

XenoPuppyXenoPuppy

Hello, I tried out this solution on a custom visual force page used for editing purposes. The problem I am running into is the user is the pop-up will appear whenever the user natvigates away from the page, like during a "save" or "cancel" operation. However I only want the warning to pop-up when the user closes the tab. 

 

Also, the pop-up will appear in other places such as entering a value for a lookup field and clicking on "today"'s date on a date field.

 

For the first part of the problem, I think it might be possible to modify the controller and use a boolean to stop the pop-up (however I haven't explored it yet).

 

But for the second part, it seems like something that is out of my control (where the pop-up is appearing for date fields and lookup fields).

 

I would appreciate any ideas/inputs, thanks a lot!