Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Closing a browser...

Posted on 2004-11-25
21
Medium Priority
?
384 Views
Last Modified: 2008-03-10
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
0
Comment
Question by:xenia27
  • 8
  • 8
  • 5
21 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12678454
whats you applet tag look like
0
 
LVL 92

Expert Comment

by:objects
ID: 12678456
> System.exit(0);

remove that line
0
 
LVL 92

Expert Comment

by:objects
ID: 12678822
your applet tag needs to include mayscript
http://www.apl.jhu.edu/~hall/java/JavaScript-from-Java.html
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:xenia27
ID: 12679246
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
 
LVL 35

Expert Comment

by:girionis
ID: 12680627
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
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 12683998
<!-- 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
 

Author Comment

by:xenia27
ID: 12693787
Nope...the browser is not closed....>"<...what should I do??
0
 
LVL 92

Expert Comment

by:objects
ID: 12693794
what browser?
0
 

Author Comment

by:xenia27
ID: 12693800
It's an IE...
0
 
LVL 92

Expert Comment

by:objects
ID: 12693804
is the js getting called?
try adding an alert() call to test
0
 

Author Comment

by:xenia27
ID: 12693808
where should I put this alert() call?
0
 
LVL 92

Expert Comment

by:objects
ID: 12693836
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
 

Author Comment

by:xenia27
ID: 12693853
Is there anyway I can popup some message in my javascript??
0
 
LVL 92

Expert Comment

by:objects
ID: 12693861
yes, use the alert() function :)

alert("Popup");
0
 
LVL 35

Expert Comment

by:girionis
ID: 12693880
0
 

Author Comment

by:xenia27
ID: 12703740
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
 
LVL 35

Assisted Solution

by:girionis
girionis earned 1000 total points
ID: 12703944
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
 

Author Comment

by:xenia27
ID: 12712384
Question,

should I have two different html files (index.html and closeWindows.html)?  will it work better if I do this way?
0
 
LVL 35

Expert Comment

by:girionis
ID: 12713520
Yes, I'd say you have two different HTML files.
0
 

Author Comment

by:xenia27
ID: 12782112
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
 
LVL 35

Expert Comment

by:girionis
ID: 12782146
:)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month20 days, 16 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question