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
JK84JK84 

How to supress the alert in onbeforeunload in JS

Hi,

 

I have a VF page with the following JS code :

 

<script type="text/javascript">

window.onbeforeunload = function jfunction()
 {
 
             call to a apex method
      
 };
       
 </script>

 

This works fine in Mozilla Firefox, but in IE, the apex method call is working only if I add a "return" statement in the "onbeforeunload" function and the return statement is causing an alert message to pop-up whenever the user is trying to navigate to another page, which is irritating to them.

 

Is there a way to supress the alert message in IE ?

 

Thanks !

Vinita_SFDCVinita_SFDC

Hello,

Are you using IE9 and windows7? If yes, then in Windows 7 and IE9, a child form is no longer allowed to submit.  The trick is to have the parent call the submit for the child form.  So the solution is to remove the onbeforeunload event from the child form and place one on the parent.  The parent JavaScript must then call the submit.

If it is not IE9 then let me know the version and what message are you getting.

JK84JK84

I'm using IE8 and Windows XP.

 

The users are getting an alert message which says "Are you sure you want to navigate from this screen ...." with a OK and Cancel button.

 

We wanted to supress the alert !!

 

Vinita_SFDCVinita_SFDC

My bad, in previous post i was referring IE8 not IE9. As you said it is IE8 you can go for previous suggestion.

 

Also refer: http://social.msdn.microsoft.com/Forums/ie/en-US/00b88378-a7f1-4148-9587-1ff17d6fa728/windows-7-problem-with-submit-in-onbeforeunload-event-in-ie?forum=iewebdevelopment

asif shaikasif shaik
Hi, 
need some help,
iam using this same js code in my page its working fine in chrome but unable to work in mozilla
action function is not calling when iam in mozilla browser but in chrome its working fine.
Any advice is appreciated.