Java Virtal

[ News ] rss

February 01, 2011

Mark Wielaard: New GPG key. Finally created a new GPG key using gnupg. The old one was a DSA/1024 bits one and 8 years old. The new one is a RSA/2048 bits one. I will use the new one in the future to sign any release tarballs I might create. pub 2048R/57816A6A 2011-01-29 Key f...

More »

February 01, 2011

Andrew Hughes: [SECURITY] IcedTea6 1.7.8, 1.8.5, 1.9.5 Released!. We are pleased to announce a new set of security releases, IcedTea6 1.7.8, IcedTea6 1.8.5 and IcedTea6 1.9.5. This update contains the following security updates: The IcedTea project provides a harness to build the source code from OpenJDK6 u...

More »

161718 19202122

[ Archives News
for 'Java Technology' ]

home > news > java technology > how to prevent an applet from being silently closed (with unsaved data)

How to prevent an applet from being silently closed (with unsaved data)

It is generally a good idea to ask the user before closing an application without saving the data. If you deploy an applet, the situation is even worse: the user may get distracted, follow some link, forget what he was doing, and close the whole browser without realizing he closed the applet too. Fortunately, it's very simple to tell the browser to display a warning. Before closing a page for any reason (reload, closing the tab, close the browser, ...), a "modern" browser will call window.onbeforeunload. If you want to alert the user, you simply need to create a javascript function that calls your applet and returns the warning message. Here is an example. This is an applet with a checkbox and a textfield. Note the two methods isPreventClose() and getPreventCloseMessage(), which define whether the applet needs to block the closing of the page and what message to prompt. package test.applet; public class MyApplet extends javax.swing.JApplet { @Override public void init() { try { java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() { initComponents(); } }); } catch (Exception ex) { } } // To be called in javascript public boolean isPreventClose() { return preventClose.isSelected(); } // To be called in javascript public String getPreventCloseMessage() { ...

Date: September, 27 2010

Others News

© Free Bootstrap Template | easy website builder | bootstrap navigation menu | bootstrap button styles | free icon maker