M
M B HONG 20
Hi all -
I am developing a web application and need to fire an on-close event
upon the user clicking the "X" button on their browser. However, i
MUST use Netscape 7.0, which does not support any native "onunload"
type of functionality. So, i had the idea of using a java applet to
access the page's DOM and fire a javascript function upon close. This
is the code I am using in my applet thus far:
import netscape.javascript.*;
import java.applet.*;
import java.awt.*;
public class CloseApplet extends Applet
{
JSObject win;
JSObject doc;
JSObject loc;
public void init()
{
win = JSObject.getWindow(this);
doc = (JSObject) win.getMember("document");
loc = (JSObject) doc.getMember("location");
setBackground(Color.black);
win.call("TestAlertOpen", null);
}
public void stop()
{
win.call("TestAlertCloseStop", null);
}
public void destroy()
{
win.call("TestAlertCloseDestroy", null);
}
}
and this is the page...
<HTML>
<HEAD>
<title>Test Java</title>
</HEAD>
<BODY>
<APPLET CODE="CloseApplet.class" CODEBASE="." WIDTH="1020" HEIGHT="150"
style="Z-INDEX: 101; LEFT: 30px; WIDTH: 1020px; POSITION: absolute;
TOP: 200px; HEIGHT: 150px" MAYSCRIPT>
</APPLET>
<SCRIPT language="javascript">
function TestAlertOpen()
{
alert ("open.");
}
function TestAlertCloseStop()
{
alert ("close, stop.");
}
function TestAlertCloseDestroy()
{
alert ("close, destroy.");
}
</SCRIPT>
</BODY>
</HTML>
When I close the page, I get an error. I realize that the error is
resulting from the fact that the applet is attempting to call a
function that is not there, due to the fact that the page has already
been closed. What I am asking is whether there is a better way (such
as an "OnBeforeUnload" event or something) that I can use to accomplish
calling a javascript function upon the browser close. Any help would
be greatly appreciated.
I am developing a web application and need to fire an on-close event
upon the user clicking the "X" button on their browser. However, i
MUST use Netscape 7.0, which does not support any native "onunload"
type of functionality. So, i had the idea of using a java applet to
access the page's DOM and fire a javascript function upon close. This
is the code I am using in my applet thus far:
import netscape.javascript.*;
import java.applet.*;
import java.awt.*;
public class CloseApplet extends Applet
{
JSObject win;
JSObject doc;
JSObject loc;
public void init()
{
win = JSObject.getWindow(this);
doc = (JSObject) win.getMember("document");
loc = (JSObject) doc.getMember("location");
setBackground(Color.black);
win.call("TestAlertOpen", null);
}
public void stop()
{
win.call("TestAlertCloseStop", null);
}
public void destroy()
{
win.call("TestAlertCloseDestroy", null);
}
}
and this is the page...
<HTML>
<HEAD>
<title>Test Java</title>
</HEAD>
<BODY>
<APPLET CODE="CloseApplet.class" CODEBASE="." WIDTH="1020" HEIGHT="150"
style="Z-INDEX: 101; LEFT: 30px; WIDTH: 1020px; POSITION: absolute;
TOP: 200px; HEIGHT: 150px" MAYSCRIPT>
</APPLET>
<SCRIPT language="javascript">
function TestAlertOpen()
{
alert ("open.");
}
function TestAlertCloseStop()
{
alert ("close, stop.");
}
function TestAlertCloseDestroy()
{
alert ("close, destroy.");
}
</SCRIPT>
</BODY>
</HTML>
When I close the page, I get an error. I realize that the error is
resulting from the fact that the applet is attempting to call a
function that is not there, due to the fact that the page has already
been closed. What I am asking is whether there is a better way (such
as an "OnBeforeUnload" event or something) that I can use to accomplish
calling a javascript function upon the browser close. Any help would
be greatly appreciated.