Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing Browser from Applet!

Status
Not open for further replies.

FOR111

Programmer
Sep 29, 2005
103
MT
Hi all,

I need some help with this issue i have been having for quite a while. I have an application running as an applet and run on a browser. The applet has a button which is an Exit button. This button should close the applet and consequently close the browser it is running it. The browser has to option eith being the parent or else a pop up..depends on the settings of the client.

I first tried it out by applying

Code:
this.exit();

and it worked great though the only disappointment is that the all the browsers (ie parent + child) closes down.

Then i tried using the JSObject which had the following:

Code:
 JSObject win =  (JSObject)JSObject.getWindow(DownloadClient.this);
 win.eval("window.close();");
 win = null;

this worked in IE6/7 but Firefox it crashed or rather due to security circumstances it gave me the following javascript error:

Code:
Scripts may not close windows that were not opened by script.

My question is...is there another method used by you guys where applets are involved?

Thanks for your considerations

Nick
 
I wouldn't call that crashing, I'd call it not allowing a programmer to decide if the user wishes to close their browser or not.

Why must people still write code that attempts to manipulate whether browsers should be opened or closed ? Just stop it !


--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Hi sedj

you're quite right about manipulating browsers but hey requirements are requirements and one has to abide by them. It wasn't my design..i'm just a middle man developer trying to fix this application.

Well i thank you for your thoughts


Nick
 
The Java sandbox shouldn't allow the applet to close the window. It may, rightly or wrongly, allow the applet to call some JS magic, but JS shouldn't be able to close a window (I can argue and often do, that it shouldn't be allowed to open them either. w3c disagrees with me.).

If your applet is signed, and the user agrees to the cert, you could just kill the process, but this messy and horrible.

I don't think you'll find a "this always works" solution, because what they want is just that bad of an idea.

[plug=shameless]
[/plug]
 
I'll go with the javascript option, that will close the window if the user wants to, but will only work if the user has javascript enabled.

Maybe a message to the user and a close button in the page could be another option.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top