|
Web Builders usually create/open new windows to show users additional
information without losing the information that they are reading.
Although you can easily open new windows with HTML, using JavaScript
to do the job gives you more control over the look and feel of the
new window you want to create/open. Let's go ahead and find out
how to create/open a new window using JavaScript.
The HTML way
<a href="http://www.your_domain.com/your_webpage.html" target="_blank">
As you can see, creating/opening a new window with HTML is extremely
easy. All you are doing is create a link to a web page that loads
in a new window - the code that opens the new window is target="_blank".
See
it work
The JavaScript way (my comments are
in red and do not have to be included
in the script)
<script language=javascript>
Since this is a script, you need the opening
and closing <script></script> statements
<!--Hide script from older browsers
function newWindow() {
myWindow = window.open ('example.html', 'myWindow', 'width=300,
height=200, toolbar=no, location=no, scrollbar=no')
This is the code responsible for opening the
new window - attributes such as "width, toolbar" set the
new window's appearance
}
//End hiding script from older browsers-->
</script>
Add this part somewhere in the BODY
<a href="javascript:newWindow()">See it work</a>
This will help you trigger the effect - that
is open the new window
See it work
Closing the window
To close the window all you have to do is add the following code
to the "new" (the page that is being opened with the script)
page.
<a href="JavaScript: parent.window.close() ;">See it work</a>
There are many other ways you can create/open a new window with
JavaScript, however the example above is one of the easiest ways
to do it.
|