aspose file tools*
The moose likes Applets and the fly likes opening  new browser window from applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "opening  new browser window from applet" Watch "opening  new browser window from applet" New topic
Author

opening new browser window from applet

Donny Frank-Rice
Greenhorn

Joined: Dec 30, 2003
Posts: 14
I am working on an applet that contains an Internet usage policy for our library patrons to view and "accept" (by clicking on the acceptance button). I have the applet working so that when a patron chooses to browse the Internet from our menu the applet appears. When the patron clicks on the acceptance button, the browser loads Google in the same page. That works for us. Is it possible to have the applet launch in a browser window that does not have an address bar or navigation buttons? If so, I would need help with rewriting the actionPerformed method so that when the patron clicks on the acceptance button that window closes and a new browser window opens.
I hope I am being clear enough. Any help would be greatly appreciated. Thanks in advance. Here is my actionPerformed method:
//This method opens Google when the acceptance button is clicked
public void actionPerformed(ActionEvent evt)
{
if (evt.getSource() == jbtAgree)
{
try
{
AppletContext context = getAppletContext();
URL url = new URL("http://www.google.com");
context.showDocument(url);
}
catch(MalformedURLException ex)
{
}
}
}
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

There's a two-argument form of "showDocument()" which takes a frame name in addition to the URL; the document is shown in that frame. If you use a non-existent name, a new window is created. Otherwise, I think there's a special name you can use ("__new" ?) which always opens a new frame, although I forget the specifics; maybe someone else remembers.
As this is not an advanced question, I'm moving this to "Applets" for further follow-ups.


[Jess in Action][AskingGoodQuestions]
Donny Frank-Rice
Greenhorn

Joined: Dec 30, 2003
Posts: 14
Sorry about that. Anyway, I figured out how to open up a new browser window by using context.showDocument(url, "_blank");.
I still need to know two things. First, once the new window is open, how do I get the original window (the one with the applet) to close? And second, I would still like to have the applet window without buttons or address bar.
Mathias Nilsson
Ranch Hand

Joined: Oct 13, 2003
Posts: 107
To close the window that opened the new window use syntax

to open without adressbar use


SCJP2 , MCP( 70-229 ) , Preparing For SCWDC
Donny Frank-Rice
Greenhorn

Joined: Dec 30, 2003
Posts: 14
Thanks, Mathias. I'll give it a try and let you know.
Donny Frank-Rice
Greenhorn

Joined: Dec 30, 2003
Posts: 14
Mathias,
I am not too sure where to place the code you suggested I try. I am still a bit new to java. Could I email you the code to my program and you could tell me where to place it? Thanks.
Mathias Nilsson
Ranch Hand

Joined: Oct 13, 2003
Posts: 107
I didn't mean that you should put the code snippet in your class file. Rather in your html document that holds the applet attribut.
// Mathias
Donny Frank-Rice
Greenhorn

Joined: Dec 30, 2003
Posts: 14
Thanks, I am new to this still.
So at which point would I place those lines, if this is my html file:
Mathias Nilsson
Ranch Hand

Joined: Oct 13, 2003
Posts: 107
Hi!
If I understand you right you have a window that contains a applet. From that window would you like to open another window and close the parent window.
If you shall open a new window without toolbar etc from the applet then i don't know, but if you click a link in the document containg the applet then you can do it with javascript. When the new window opens you can close the parent window.
// First html page with the applet

When you have pressed the link and the other window opens
Mathias Nilsson
Ranch Hand

Joined: Oct 13, 2003
Posts: 107
It seems to me that you can use the
netscape.javascript.*; package. It enables opening a new window from
an Applet without the toolbar. Search google for this.
here is a good page on the matter
// Mathias
[ April 14, 2004: Message edited by: Mathias Nilsson ]
Mathias Nilsson
Ranch Hand

Joined: Oct 13, 2003
Posts: 107
Ok! I've managed to open a new window from java without a toolbar.
First! Add netscape.javascript to your classpath. If you are using jdk1.4
then you can reference jdk1.4\jre\lib\jaws.jar. It contains the netscape package.
when this is done you create your html file. Dont forget to add the element
MAYSCRIPT to your applet description.
Se example. ( HTML file that contains the applet )

And here is our Test class.

Try it out. Pretty cool
Donny Frank-Rice
Greenhorn

Joined: Dec 30, 2003
Posts: 14
Thanks a bunch. I don't have time to try it out right now (and probably won't until tomorrow), but I will give it a try as soon as I can and let you know if it works out. Again, thank you for taking the time. I am still something of a newbie here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: opening new browser window from applet