Andreas Rozek Hints for Reading List of Recent Changes Guestbook Entry Contact the Author  Deutsche Version  HomePage Previous Topic Next Topic  First Page of Current Topic Next Page Previous Page

Applet_04

Applets have some (albeit rather limited) control over the web browser they are running in. "Applet_04" shows how to switch between several HTML pages.

Please, also consider my "Hints for Reading" and the "List of Recent Changes"!

Applet_04 snapshot

The applet on the left side instructs the browser to display one of several test documents. Choose the desired location and press the "Show" button. The page that is going to appear now will tell you how to proceed.

This applet does not work from within an applet viewer (Applet viewers are "allowed" to ignore the showDocument method which is demonstrated here).

Switching HTML Documents

From within an applet it is possible to instruct the browser to display another HTML document with a given URL. This web page may be shown

  • in the current frame
    The desired document is loaded into the current browser frame and replaces the page that contains the applet. The applet itself is "stopped" (i.e., the browser invokes the applet's stop method) in order to indicate that it became invisible. As soon as the user comes back to the original page, the browser will start the applet again.
  • in the parent frame
    Provided that the applet resides in a nested frame, the new document is shown in the parent of the current frame (that feature cannot be shown here as this document doesn't contain any (sub-)frames).
  • in the top-most frame
    Provided that the applet resides in a nested frame, the new document is shown in the top-most frame of the current browser display (that feature cannot be shown here as this document doesn't contain any (sub-)frames).
  • in a new unnamed top-level window
    The underlying browser opens a new top-level window and loads the desired document into that window. If the new web page doesn't define a <title> then no title is shown in the window's title bar.
  • in a new named top-level window
    The underlying browser opens a new top-level window and loads the desired document into that window. If the new web page doesn't define its own <title> then the given one is shown in the window's title bar - otherwise the document's definition is used.

All that has to be done is to invoke

  showDocument(URL);

or

  showDocument(URL, target);

and specify the URL of the desired HTML document and - if need be - the desired target display.

Source Code

The source code of this applet is available for download:

Additionally, the following HTML files are required to run "Applet_04":

Disclaimer

Please, consider also the author's Disclaimer!

http://www.Andreas-Rozek.de/Java/JavaKurs/Applet_04/Applet_04.html    (last Modification: 01.05.2002)