Click here to Skip to main content
16,020,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using the following code to pop up an alert when user tries to close the window.
But, instead of normal alert, i need some button on the alert that helps me to redirect to some other page.

JavaScript
<script language="JavaScript" type="text/javascript">
  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
  
    return "Are you sure you want to exit?";
  }
</script>



Please help.
Posted

1 solution

You cannot "modify alert". And it would make little sense. Please see my recent article which explains all related issues in detail: Modal Popup From Scratch[^].

In this article, I,first of all, explain the concept of "modal popup". Main point is: "alert", "confirm" and "prompt" are hardly can be considered suitable for any production-level application.

You don't have to use my code. First of all, my article explains how to create such facility by yourself, and explains where you can find other implementations. First of all, it's jQuery UI dialog and numerous 3rd-party plug-ins to it.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900