0

I am using OAF framework which automatically binds a function to onbeforeunload event(like onbeforeunload="_savePageStateIE()").

I am using the below code unbind standard func and bind a custom func. But it is working in all browsers except IE.

<html>
<script>
window.onbeforeunload=null;
window.onbeforeunload = confirmExit;

function confirmExit()
{
return "You have attempted to leave this page.";
}
</script>
<body onbeforeunload="_savePageStateIE()">
<h1 style="color:red">Hello World</h1>
</body>
</html>
Alex Char
  • 32,879
  • 9
  • 49
  • 70
Arup Nayak
  • 55
  • 7

1 Answers1

0
<body onload="myFunction()">
  <!-- put html code here -->
</body>

function myFunction() {
   var redirect = confirm("Redirect to url ?");
   if (redirect == true) {
       window.location.href = 'url'; //redirect to url.
   }
}

Or should be like this

var warning = true;
window.onbeforeunload = function() { 
  if (warning) {
    return "You have made changes on this page that you have not yet confirmed. If you navigate away from this page you will lose your unsaved changes";
  }
}

$('form').submit(function() {
   window.onbeforeunload = null;
});

I found upper one from here :- Url

Especially for ie..

<script>
    $(window).on('beforeunload', function(){
        return "This should create a pop-up";
    });
</script>
Community
  • 1
  • 1
Just code
  • 13,553
  • 10
  • 51
  • 93