Window
Window
window
document
Dialog boxes
It is used to provide some information to users.
Type of Dialog box:-
• Alert
• Confirm
• Prompt
alert ( ) Method
This Window object’s method is used to display data in alert dialog box. alert
really should be used only when you truly want to stop everything and let the
user know something.
Syntax:- window.alert( ) or alert ( )
Ex: - window.alert(“Hello World”);
window.alert(variable);
window.alert(4+2);
window.alert(“Hello World” + variable);
confirm ( ) Method
This Window object’s method is used to display a message for a user to
respond to by pressing either an OK button to agree with the message to a
Cancel button to disagree with the message. It returns true on OK and false on
Cancel.
Syntax:- window.confirm( ) or confirm ( )
Ex: - window.confirm(“Are you sure ?”);
if(confirm(“Do you want to Delete ?”)) {
document.write(“Data deleted”);
} else {
document.write(“Action Cancelled”);
}
prompt ( ) Method
Window object’s method prompt() can be used to get input from the user,
named prompt. The prompt( ) method displays a dialog box that prompts the
visitor for input.
Once the prompt function obtains input from the user, it returns that input. If
the user press the cancel button in the dialog or close box, a value null will be
returned.
Syntax: - prompt(text, defaultText)
Ex:- prompt(“Enter Your Name: “, “name”);
prompt(“Enter Your Roll No. : “);
open ( ) Method
The open( ) method creates a new secondary browser window, similar to choosing New Window
from the File menu. It returns a Window object representing to the newly created window. If the
window couldn't be opened, the returned value is instead null.
Syntax: - window.open (URL, name, features, replace)
URL – URL indicates the document to load into the window. If no URL is specified, a new
window with about:blank is opened
Name – Specifies the target attribute or the name of the window. The following values are
supported:
_blank - URL is loaded into a new window. This is default
_parent - URL is loaded into the parent frame
_self - URL replaces the current page
_top - URL replaces any framesets that may be loaded
open ( ) Method
Syntax: - window.open (URL, name, features, replace)
Features – It is a comma delimited string that lists the features of the window.
Replace – It indicates whether or not the URL specified should replace the window’s contents.
This would apply to a window that was already created. Value can be true/false.
Ex: -
var newWindow = window.open(“http://www.geekyshows.com” , “_self” , “height=100,
width=100”)