Closing Windows

By: aathishankaran Emailed: 1785 times Printed: 2615 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

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. 

Displaying Message Boxes 

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")  





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)


document.write("Please use Netscape with JavaScript</b></






User Input 

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





<title> Expression eval</title>


function com (form) {







<input type="text" name="expression" > =

<input type="text" name="result">


<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=’’”>







JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.

Bookmark and Share


Be the first one to add a comment

Your name (required):

Your email(required, will not be shown to the public):

Your sites URL (optional):

Your comments:

More Tutorials by aathishankaran
Web Security Issues
The Web User's Perspective
Server-side plug-Ins
The best way to avoid security vulnerabilities with new server
JavaScript Security
Window Object
Working with Status Bar Messages
Retrieving a Portion of a String
Referencing Windows
Math Object
Frame Object
Document Object
Closing Windows
Built-in Object in Javascript
Textarea Object

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: ` Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
JSP Example to connect to MS SQL database and retrieve records
What are the different scopes in JSP?
JSP CheckBox Example
JSP Alert Example
Comparison operators in JSP
Sending Email using JSP
Uploading an Image to a Database using JSP
Arithmetic Evaluation Using the Expression Language in JSP
The Advantages of JSP
Disabling Scriptlets in JSP using web.xml
The Request Object in JSP
Writing your first JSP page
Uploading a file to a server using JSP
Deploying an Individual JSP on Tomcat
Automatically Refreshing a JSP
Most Emailed Articles (in JSP)
Calling JSP from a batch file
Simple HTML-Building Utilities
Handling Events
The Tag Life Cycle with Attributes in JSP
JSP Program for display Date
Sessions in JSP
The Advantages of JSP
Using a DataSource from WebLogic in a JSP
The JSP Program running first Time.
JSP pages in servlet
Combining Scriptlets with HTML
Declaring variable in JSP
An Example Using Servlet Initialization and Page Modification Dates
Password Object