Closing a browser...

Hi,


Here is my codes trying to close a browser through my JApplet program...but it's not working...what's wrong with my codes??


// in my applet
getAppletContext().showDocument(new URL("javascript:CloseWindow()"));             
System.exit(0);

// in my html
  <head>
  <SCRIPT>
  function CloseWindow()
  {
        window.close();
  }
  </SCRIPT>
  </head>


Any suggestion???


Xenia
xenia27Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
whats you applet tag look like
0
objectsCommented:
> System.exit(0);

remove that line
0
objectsCommented:
your applet tag needs to include mayscript
http://www.apl.jhu.edu/~hall/java/JavaScript-from-Java.html
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

xenia27Author Commented:
I'm confused about this mayscript...
here is my html...what should I do?
Should I have this mayscript?  If so, where should I put it????
////////////////////////////////////////////////////////////////////////////////////////
<!-- saved from url=(0022)http://internet.e-mail -->
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
  <head>
  <SCRIPT>
  function CloseWindow()
  {
        window.close();
  }
  </SCRIPT>
  </head>

  <body>      
<!--"CONVERTED_APPLET"-->
<!-- CONVERTER VERSION 1.3 -->
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="610" height="600"
codebase="http://java.sun.com/products/plugin/1.4/jinstall-14-win32.cab#version=1,4,0,mn">
<PARAM NAME = CODE VALUE = ACS1170View.class >
<PARAM NAME = ARCHIVE VALUE = "ACS1170.jar" >
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.4.1_02">
<PARAM NAME="scriptable" VALUE="false">
</object>
<COMMENT>
     <!-- [if !IE]>  -->
     <object archive="ACS1170.jar" height="600" width="600"></object>
     <!-- <![endif]-->
</COMMENT>
</object>
  </body>
</html>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
0
girionisCommented:
Have a look here: http://www.rgagnon.com/javadetails/java-0172.html to find out how you can call JavaScript from within an applet.
0
objectsCommented:
<!-- saved from url=(0022)http://internet.e-mail -->
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
  <head>
  <SCRIPT>
  function CloseWindow()
  {
       window.close();
  }
  </SCRIPT>
  </head>

  <body>      
<!--"CONVERTED_APPLET"-->
<!-- CONVERTER VERSION 1.3 -->
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="610" height="600"
codebase="http://java.sun.com/products/plugin/1.4/jinstall-14-win32.cab#version=1,4,0,mn">
<PARAM NAME = CODE VALUE = ACS1170View.class >
<PARAM NAME = ARCHIVE VALUE = "ACS1170.jar" >
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.4.1_02">
<PARAM NAME="scriptable" VALUE="true">
<PARAM NAME="mayscript" VALUE="true">
</object>
<COMMENT>
     <!-- [if !IE]>  -->
     <object archive="ACS1170.jar" height="600" width="600"></object>
     <!-- <![endif]-->
</COMMENT>
</object>
  </body>
</html>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
xenia27Author Commented:
Nope...the browser is not closed....>"<...what should I do??
0
objectsCommented:
what browser?
0
xenia27Author Commented:
It's an IE...
0
objectsCommented:
is the js getting called?
try adding an alert() call to test
0
xenia27Author Commented:
where should I put this alert() call?
0
objectsCommented:
in the javascript method, just need something to test if the javascript is getting called.


also try:

getAppletContext().showDocument(new URL("javascript:window.close();"));        
0
xenia27Author Commented:
Is there anyway I can popup some message in my javascript??
0
objectsCommented:
yes, use the alert() function :)

alert("Popup");
0
girionisCommented:
0
xenia27Author Commented:
sorry~  I thought the problem was solved...I mean it's solved...but somehow...not sure why, it's not working again...>"<
 
OK...here is what I did...
  <SCRIPT>
  alert("Before CloseWindow");  <--- I do saw this one..
  function CloseWindow()
  {
      alert("Before window.close() called");
        window.close();
      alert("After window.close() called");
  }
  </SCRIPT>

// in my applet
getAppletContext().showDocument(new URL("javascript:window.close();"));

I still don't see my IE browser is closed...not even ask user whether they wants to close the IE or not...

what should I do now?
0
girionisCommented:
Put the JavaScript above into a fiel called closeWindow.html in the same folder as your applet class.

Then do:

getAppletContext().showDocument(new URL("closeWindow.html"));

and your closeWindow.html should be:

<html>
<SCRIPT>
  alert("Before CloseWindow");  <--- I do saw this one..
  function CloseWindow()
  {
     alert("Before window.close() called");
       window.close();
     alert("After window.close() called");
  }
  </SCRIPT>
<body onLoad="window.opener=null;closeWindow();">
</body>
</html>
0
xenia27Author Commented:
Question,

should I have two different html files (index.html and closeWindows.html)?  will it work better if I do this way?
0
girionisCommented:
Yes, I'd say you have two different HTML files.
0
xenia27Author Commented:
Unfortunetly, my project got canceled....cannot test on the machine...but I do believe these methods work...of course...
So thank you for helping me...^^
0
girionisCommented:
:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.