Department of Computer Engineering: Window - Open (URL, Name, Specs, Replace)
Department of Computer Engineering: Window - Open (URL, Name, Specs, Replace)
COMPUTER ENGINEERING
Experiment No: 11
Title of Experiment Develop a webpage for placing the Window on the screen and working
with child window.
Theory:
If a document contain frames (<iframe> tags), the browser creates one window object for the
HTML document, and one additional window object for each frame.
The open() method opens a new browser window, or a new tab, depending on your browser
settings and the parameter values.
URL Optional. Specifies the URL of the page to open. If no URL is specified,
name Optional. Specifies the target attribute or the name of the window.
Page | 1
replace Optional. Specifies whether the URL creates a new entry or replaces
Example
<html>
<body>
<p>Click the button to open a new browser window.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
window.open("https://www.microsoft.com/en-in/");
}
</script>
</body>
</html>
Output:
Page | 2
Child window
The opener property returns a reference to the window that created the
window.
When opening a window with the window.open() method, you can use this
property from the destination window to return details of the source (parent)
window.
window.opener.close() will close the source (parent) window.
Example
<html>
<body>
<p>Click the button to write some text in the new window and the source
(parent) window.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
var myWindow = window.open("", "myWindow", "width=200,height=100");
myWindow.document.write("<p>Hello 'SHEKHAR'</p>");
myWindow.document.write("<p>This is 'myWindow'</p>");
myWindow.opener.document.write("<p>This is the source window!</p>");
}
</script>
</body>
</html>
Output