Closing Windows
By: aathishankaran Printer Friendly Format
To close a window, you can use the window object's close ()
method. If you are closing the current window, your method call is simply
window.close (). Unlike other window object methods, such as alert () or
setTimer (), the close () method must always accompany an object reference. If
you use close () by itself, you could close the current document rather than the
window, depending on the context of the method call. The reason is that the
document object has a close () method, too.
Dialog is one of the useful components in windows to display certain information.
Alert
is used to display a message. The Syntax is as follows
alert
("Message")
You have a new method called confirm to get a confirmation.
The syntax is as follows.
Variable
= confirm ("Message")
<html>
<head>
<script>
var
name=prompt("Enter name","anonymous")
function
drawrule(width) {
document.write("<HR
WIDTH="+width+"%>")
}
if (!confirm("Click
ok if you are using Netscape")){
document.write("<center><b>Dear
"+name)
drawrule(50)
document.write("Please
use Netscape with JavaScript</b></
center>");
}
</script>
</head>
</html>
A third message box that you can use for obtaining user
input is invoked with the prompt () method of the window object. Use the prompt
dialog box when you want to obtain a value from a user. This dialog box features
a message, an edit box for user input, and OK and Cancel buttons. The prompt ()
method has the following syntax:
returnValue
= [window.]prompt(message, defaultReply)
As you can see, in addition to specifying the message of
the dialog box, you need to specify a defaultReply parameter. This value becomes
the default text inserted in the edit box of the message box. You must specify
this parameter, even if you have no default value. If the user clicks OK, the
prompt () method returns the string value entered by the user. If nothing is
entered in the edit box, an empty string ("") is returned. However, if
the user clicks Cancel, a null value is returned.
if you select cancel
Example
<html>
<head>
<title>
Expression eval</title>
<script>
function
com (form) {
form.result.value=eval(form.expression.value)
}
</script>
</head>
<body>
<form>
<input
type="text" name="expression" > =
<input
type="text" name="result">
<p>
<input
type="button" name="a"
value="Compute" onClick="com(this.form)">
<input
type="button" value="Clear" onClick="this.form.expression.value=’’
; this.form.result.value=’’â€>
</form>
</body>
</html>
Output
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview