Web Hosting
We've partnered with HostGator for reliable, affordable hosting starting at $3.95/mon. Use coupon code "javascriptkit25" for 25% off any package.

Reloading, closing, loading new content into a window using JavaScript

With JavaScript, we can write code that replaces the "reload" and "close" button of our browser.

To reload a window, use this method:


Here's an example:

To close a window, use this method:


I was almost tempted to provide an example!

Ok, we can also load new content into a window using JavaScript-this is similar to the <a> tag in html, only now, using JavaScript, we have more control over this process.

The basic syntax when loading new content into a window is:


This is exactly the same as

<a href="></a> //if we use html

Lets provide an example, where a confirm box will allow users to choose between going to two places:

<script type="text/javascript">
function warp(){
var ok=confirm('Click "OK" to go to CSS Drive, "CANCEL" to go to CodingForums')
if (ok)
Copyright 1997-2014 JavaScript Kit. NO PART may be reproduced without author's permission.