Uses of the New Window Command for Web Sites - Examples of common new window uses
(Page 4 of 5 )
Take a look at the code below for the file test.html:
test.html
<html>
<head>
<title>Uses of the New Window command demonstration</title>
<script type="text/javascript">
function testOpen() {
window.open('http://www.amazon.com/','_blank');
}
</script>
</head>
<body>
<h1>window.open() demo</h1>
<a href="#" onclick="testOpen();">go to Amazon</a>
</body>
</html>

Picture 4: window.open() demonstration 1
Look at the screenshot. When you click the link, a new common window is opened.
As you saw in the <a href="#" onclick="testOpen();">go to Amazon</a> link, we did not specify the target URL in the href attribute, but added an onclick attribute. A literal JavaScript string is declared as the event handler. When the user clicks the link, the CLICK event is fired and the content in the onclick attribute will be evaluated, so the testOpen() function is invoked. In the testOpen() function, it uses the window.open() to open http://www.amazon.com/ in a new blank window.
b) Open a customized window
You can add some feature options using the open() method.
window.open('http://www.amazon.com', '_blank', 'width=200, height=200,
menubar=no, toolbar=no, location=no, scrollbars=no, status=no, resizable=no');

Picture 5: window.open() demonstration with customized new window
When you click the link, a new 200*200 window will be opened without the menu bar, toolbar, location, scrollbars, and status bar. And the window size is unchangeable. It sounds cool, right? Try it.
Next: Advanced Usage >>
More HTML Articles
More By Stephen Davies