I’m presently writing JavaScript, on clicking the close button in the window, I should get a confirm box. In the confirm box, I should display some message and there should be cancel and continue buttons.
On clicking cancel, the window should not be closed, but on pressing continue, the window should be redirected to another jsp.
Can someone please help me with this code? I tried using the custom confirm box, but that seems to return only a string and it cannot be used to redirect to a page.
This is impossible. You cannot redirect the user to another page when they close the window. This is for security reasons.
To display a confirm box when closing the window, you can use the
onbeforeunloadevent. This will ask the user if they wish to leave the page or not. The confirm box is rendered by the browser, all you can customize on is the text.When the user leaves the page, you can use the
onunloadevent, but again, you cannot redirect them (you can make an AJAX call, but you cannot redirect the browser).