JavaScript Window Object Open Method Part 2
In this JavaScript tutorial, you will learn about JavaScript Window Object Open Method, features of window object open method – scrollbars, status, titlebar, toolbar, top, width, innerHeight, innerWidth, outerHeight, outerWidth and hotkeys
scrollbars:
Syntax: scrollbars=yes|no|1|0
The scrollbar feature denotes whether or not the scroll bars should be displayed. The default value of the scrollbars feature is YES, displaying the scroll bars. If the value of the scrollbars feature is set to NO by the user, then the scroll bars are not displayed.
status:
Syntax: status=yes|no|1|0
This allows the user the provision of adding the status bar or not. The default value to the status feature is YES, which adds the status bar. If the user sets the value of the status feature to NO, then the status bar is not added.
titlebar:
Syntax: titlebar=yes|no|1|0
JavaScript provides the option to add the status bar or not and the same option is provided for the visibility of the title bar. The titlebar feature allows the user to denote whether or not the title bar should be displayed. The default value to the titlebar feature is YES, displaying the title bar. If the value of the titlebar feature is set to NO by the user then the title bar is not displayed.
NOTE: this is called only if the application called is an HTML application, otherwise, calling the titlebar feature is not taken into account.
toolbar:
Syntax: toolbar=yes|no|1|0
Like the scroll bar, the toolbar is used to denote whether the browser’s tool bars should be displayed or not. The default value of the toolbar feature is YES, displaying the tool bar. If the value of the toolbar feature is set to NO by the user, then the tool bar is not displayed.
innerHeight:
Syntax: innerHeight=pixels
This feature is used to specify the inner height of the window. The value for this feature is given in pixels.
innerWidth:
Syntax: innerWidth=pixels
This feature is used to specify the inner width of the window. The value for this feature is given in pixels.
outerHeight:
Syntax: outerHeight=pixels
This feature is used to specify the outer height of the window. The value for this feature is given in pixels.
outerWidth:
Syntax: outerWidth=pixels
This feature is used to specify the outer width of the window. The value for this feature is given in pixels.
hotkeys:
Syntax: hotkeys=yes|no|1|0
If the user sets the value of the hotkeys feature to NO, then the window’s usage or function of hotkeys is disabled.
replace:
Another optional attribute that is passed to the open() method of window object is the replace method. This attribute is mentioned in the syntax of the open() method in above description. This specifies the way the entry in the history list is handled. This method is used to specify whether the URL has to create a new entry in the history list or replace the current entry in the history list. The replace attribute can take the values of true or false. The true value specifies that the URL replaces the current document in the history list. The false value specifies that the URL creates a new entry in the history list.
Let us see an example to understand the usage of open() method of window object in brief:
<head> <body> html>
<html>
<script type="text/javascript">
function exforsys()
{
window.open("http://exforsys.com","_blank","toolbar=yes,
location=yes, directories=no, status=yes, menubar=no,
scrollbars=yes, resizable=no, width=300, height=500")
}
script>
head>
<form>
<input type="button" value="Click Here to Display
Window!!!" onclick="exforsys()">
form>
body>
The output of the above example is a button with the message:
When this button is clicked, the URL http://exforsys.com displays in a new window. This is because the first argument mentioned is http://exforsys.com and the second argument mentioned is _blank, denoting that the URL loads into a new window. The URL displayed in the new window has its window width as 300 and its height as 500. The value of width and height are mentioned as 300 pixels and 500 pixels respectively. The windows displayed have the scroll bars, tool bar, status bar displayed because the value of scrollbars, status and toolbar is set to yes, making these visible in the window. The window displayed is not resizable and is fixed in size because the resizable feature is set to no. The value of the menubar is set to no, displaying no menu bars in the final output window.