The Window.open() method

//Create new Window

options = "toolbar=0,status=0,menubar=0,scrollbars=0," +
    "resizable=0,width=300,height=200";
newwindow = window.open("", "mywindow", options);
newwindow.document.writeln(LocalTime);
newwindow.document.write(contents);
newwindow.document.close();

When I want to open a new window, first I think of a name for the window, such as MyWindow. Then I open the window with this command:

MyWindow = window.open()

The window.open method can have 3 optional parameters. Parameters are things you can type inside the parentheses to specify how you want the window to open. The 3 parameters are:

  1. A URL so that the window contains a specific HTML document.
  2. A title for the window
  3. A set of options for the window's appearance, including height and width.

For example, let's say I created a page called mytest.htm. It might be as simple as this:

<HTML>

<HEAD>
    <TITLE>Test Page </TITLE>
</HEAD>

<BODY>
    This is only a test
</BODY>

</HTML>

I could open it into a new window like this.

NewWindow = window.open("mytest.htm")

The second parameter is the default title of the window. The third parameter allows you to set a long list of options about your new window. Here are the options you can set.

Option choice description
toolbar yes/no or 1/0 Display toolbar
status yes/no or 1/0 Display status bar at bottom of window
menubar yes/no or 1/0 Display menubar
scrollbars yes/no or 1/0 Display horizontal and vertical scrollbars
resizable yes/no or 1/0 Window can be resized
location yes/no or 1/0 Display location box
directories yes/no or 1/0 Display directory buttons
width # of pixels Exact width of new window
height # of pixels Exact height of new window

If I want to open the mytest document in a small, 100 x 100 pixel window I would type this:

NewWindow = window.open("mytest.htm","mywindow","width=100,height=100")

As you can see, the window.open() command can get very long. One solution is to specify the options in a seperate variable, which I call "options." Then your command would look like this:

options = "width=100,height=100"
NewWindow = window.open("mytest.htm","mywindow",options)

Let's try creating a larger list of options. Experiment with different options in this table. A variable called options will be created below with your list of window options.


results matching ""

    No results matching ""