-1

In my application i have to alert user to signout on browser close. For that i have used the javascript as below

<body scroll="no" onbeforeunload="browerClose()">
<script language="JavaScript" type="text/javascript">
function browerClose()
{
 window.alert("Click OK to SignOut");
 window.location.href = "http://localhost:8086/egs/ervlet?pri=logOut";

}

this is Working for IE ,but not works for FireFox, Wats the Problem....Any Suggesstions Thankxx in Advance,

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Aravinth
  • 363
  • 2
  • 10
  • 33

2 Answers2

0

I would suggest you move the javascript function to the head section of the HTML document. That way it is working for Firefox. Maybe this is because HTML documents are processed in sequential order and you need to define the function before you can use it.

Do something like this:

<head>
<script language="JavaScript" type="text/javascript">
function browerClose()
{
 window.alert("Click OK to SignOut");
 window.location.href = "http://google.com";
}
</script>
</head>
<body scroll="no" onbeforeunload="browerClose()">
<!-- you code here -->
0

onbeforeunload event will not work from fire fox version 26 if u used any custom alert message in your application which means you need to perform x operation when closing browser/tab or refreshing page but you put alert message in function which will be called from onbeforeunload then the x (update) operation will not happened.

<html>
<head>
<script>
   function unloadfunction() {
      alert('test');
      // update employee ID in Database
   }
</script>
</head>
<body onbeforeunload="unloadfunction();">
</body>
</html>