You are on page 1of 2

Experiment No. 11.

1
Aim: Develop a Web page for placing the window on the screen.
Theory:
Placing a window on screen:
JavaScript's window object represents the browser window in which document is displayed.
Opening a window: open () method of Window object is used to create a new browser window.
Syntax: var win_name=window.open(URL,name,features);
- URL - It gives path for the document to be loaded into the window.
- name - It is the name of window which can be used for referencing it using target attribute of
HTML links.
- features - It is a comma-delimited string that lists the features of the window such as left, top,
height, width, etc.
A open window can be closed with close( ) method of window object. To close the window, a variable name
is used that points to the window to be closed.
Syntax: windowvariable.close( );
Example:
var mywindow=window.open(“http://www.google.com”,”google”, ”top=100,left=100,height=200,width=200”);

Creating a web page in a new window:


After opening a new window, one can create an HTML document can display it as web content using
JavaScript. A document.write method is used to create a web page in a new window.
Syntax:- windowname.document.write(“HTML tag”);
HTML tag is written inside bracket within double-quotes.
Example:- mywindow.document.write(“<HTML>”);

Programs:
Opening and closing new window on screen:
<html>
<head>
</head>
<body>
<button onclick="openwindow()">open window</button>
<button onclick="closewindow()">close window</button>
<script type="text/javascript">
var mywindow;
function openwindow()
{
mywindow=window.open("http://www.yahoo.com","yahoo","wid
th=400,height=400,top=200,left=200");
}
function closewindow()
{
mywindow.close();
}
</script>
</body>
</html>
Creating a web page in new window:
<html>
<head></head>
<body id="body">
<button onclick="openwin()">open window</button>
<script type="text/javascript">

function openwin()
{
mywindow=window.open("","","height=400,width=400,left=100,top=100");
mywindow.document.writeln("<html>");
mywindow.document.writeln("<head>");
mywindow.document.writeln("<body>");
mywindow.document.writeln("<h1> Hello</h1>");
mywindow.document.writeln("<h1><font
color=red>Welcome</font></h1>");
mywindow.document.writeln("</body>");
mywindow.document.writeln("</html>");
mywindow.document.close();
mywindow.focus();
}
</script>
</body>
</html>

Practical Related Question(observation):


1. Write use of focus() method with respect to window.
Ans.

2. Differentiate between moveBy() and moveTo() methods.


Ans.

3. Differentiate between resizeBy() and resizeTo() methods.


Ans.

4. Differentiate between scrollBy() and scrollTo() methods.


Ans.

5. Write JavaScript code to open five windows at a time.


Ans.

Conclusion:
With all the concepts based on working with window , successfully executed all programs with correct
output.

You might also like