How can I open a browser window without menubar from within an applet?

Daniel Tatro

The applet needs to tell JavaScript to open the window, instead of using showDocument() from the applet.

Here's the JavaScript to open the window without a menubar:

<script language="JavaScript">
  function jsfunction(strURL){, "_blank", 
      "height=300 width=400 scrollbars=yes");
JSObject defined

Java applets may need to perform Java to JavaScript communication to access the Document Object Model (DOM) or to call JavaScript functions on an HTML page. Internet Explorer and Navigator allow communication between Java to JavaScript through the Java wrapper class netscape.javascript.JSObject.

Java Plug-in supports Internet Explorer and Netscape Navigator on various Win32 platforms and Solaris platforms. JSObject provides an easy way to access the DOM of a HTML page. Because different browsers implement DOM differently, using JSObject in a Java applet may yield different behaviors in Java Plug-in, depending on the underlying DOM implementation in the browser. For more details about the DOM implementation in your browser, please consult the development guide for your browser.

Due to security reasons, JSObject support is not enabled in Java Plug-in by default. To enable JSObject support in Java Plug-in, a new attribute called MAYSCRIPT needs to be present in the EMBED/OBJECT tag.

JSObject in action

This example applet implements the JSObject. The simple applet allows the user to press a button. The incurring event collects an applet parameter ("URLParam" - a URL or web page) and sends it to a JavaScript function ("jsfunction") on the page. The JavaScript function loads the URL into a new window with no menubar.

<APPLET code="MyApplet.class" align="baseline" width="150" height="30">

Portions taken from Sun.

Here's the applet source:

import netscape.javascript.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

class MyApplet extends Applet implements ActionListener {
  String URLParam;

public void init() {
  Button b = new Button("Click to call jsfunction()");
public void actionPerformed(ActionEvent event) {
public void triggerjs(){
// Get the URL parameter
  URLParam = getParameter("URLParam");		
// Get a handle on the window	
  JSObject win = JSObject.getWindow(this);	
// Set the argument object
  Object[] args = {URLParam};			
// Call jsfunction() in HTML page"jsfunction", args);			
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact