How to show popup when user tries to close browser window?

P

Pasha

Hi all,

I want to show popup when user tries to close browser
window. Like "Are you sure you want to close it" or "please logof
first" etc.If user clicks yes then browser window must not get closed.
Will you please tell me how should I do it?


I have tried by using "onbeforeUnload()" event but if user
uses "alt+f4" to close
it will not work. And one more thing is that this solution is for IE
only I want the solution for
all browser.


If any one knows please tell me.


Waiting for your reply................


Thank you,


Prashant
 
D

Duane Evenson

Pasha said:
Hi all,

I want to show popup when user tries to close browser
window. Like "Are you sure you want to close it" or "please logof
first" etc.If user clicks yes then browser window must not get closed.
Will you please tell me how should I do it?


I have tried by using "onbeforeUnload()" event but if user
uses "alt+f4" to close
it will not work. And one more thing is that this solution is for IE
only I want the solution for
all browser.


If any one knows please tell me.


Waiting for your reply................


Thank you,


Prashant

Change the default window behaviour:
myFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

and add a WindowListener to your main window:
myFrame.addWindowListener(WindowL);

Wherein you can handle your exit operations in
public void windowClosing(WindowEvent e) , including having a
with a line like this:
JOptionPane.showMessageDialog(null, "Bye, Don't forget to write.");
to have a farewell dialog box appear.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top