Professional Documents
Culture Documents
Exp11 1
Exp11 1
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”);
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>
Conclusion:
With all the concepts based on working with window , successfully executed all programs with correct
output.