Window Object

By: aathishankaran Viewed: 153247 times  Printer Friendly Format    


Creating, a window 

To create a window use the following syntax: 

            Window_object_name=]open(“url","Window name"[,"attribute"]) 

The URL parameter specifies what content appears in the new window. If you specify a value, the browser attempts to locate and display the specified document: 

        newWindow= window.open(“http://www.java-samples.com", "Home Page","") 

Alternatively, you can display a blank page by specifying an empty string ("") as the URL parameter. Use this technique if you want to create an HTML page dynamically using JavaScript: 

newWindow = window.open(“", “DynamicPage", “")

newWindow.document.write(“<Hl>Document created using JavaScript.</Hl>") newWindow.document.close () 

Specifying Window Attributes 

The windowAttributes parameter is important as you display windows because it

Lets you customize the look of the window you are opening. The window Attributes parameter is optional; not including it gives you a window identical to the current one with respect to attributes. 

Attribute

Description 

width

Width of window in pixels

height

Height of window in pixels

toolbar

Show/hide browser toolbar

Menubar

Show/hide browser menu bar

Scrollbars

Show/hide browser horizontal and vertical scrollbars

resizable

Allow/disallow resizing of browser window

Status

Show/hide browser status bar

Location

Show/hide URL location box

Directories

Show/hide secondary toolbar (Netscape)

Copyhistory

Copy current window's Go history for new window

             The width and height attributes specify the dimensions of the window in pixels.

The remaining attributes are set by using Boolean values: True values are either 1, yes, or the attribute alone; false values are either 0, no, or more simply, leaving it out altogether. For example, if you want to display the new window with only a toolbar and menu bar, you use the following line: 

newWindow = window.open("”,"my Window”, "toolbar=l,   menubar=l”) 

The following syntaxes are also valid: 

newWindow = window. open ("", "myWindow” , "toolbar=yes , menubar=yes”)

newWindow = window. open (" “, "myWindow “ , "toolbar, menubar”) 

As you can see, you can simply leave out those attributes that are not specified. They are assumed to have false values. 

Example

<Html>

<Head>

<Title>

Example For Window Object

</Title>

<Body>

<Hl>Example for Window Object</Hl>

<H2></H2>

<Hr>

<Form Name=form1>

<Center>

<Input Type=Button

Name=btn1

Value=”Open java”

onClick=” window.open(‘http://www.java-samples.com’,’’);

“>

<Input Type=Button

Name=btn2

Value=”Help”

onClick=”

win=window.open(‘’,’’,'toolbar=0, menubar=0, status=0')

win.document.write ('<H1>Help For The page</H1>' );

win.document.write('<ol>') ;

win.document.write ('<li>Click on the Open Hotmail' );

win. doo.nnent. write ( '<li>The Hotmail web page is loaded') ;

win.document.write('<li>If Hotmail is not loaded then, You may not have connected to Internet');

win.document.write('</ol>');

“>

<Hr>

</Center>

</Form>

</Body>

</Html>



Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial