Categories:

Windows and JavaScript

Using JavaScript, we can manipulate windows in a variety of ways, such as open one, close it, reload its page, change the attributes of the new window etc.

Opening a new window using JavaScript

Lets start at the very top- "How do I open a new window in JavaScript?" Appropriately enough, by using a JavaScript method called "window.open()":

window.open("http://www.dynamicdrive.com")

When the above code is run, a new window opens containing the specified URL, similiar in behavior to the "target" attribute of a link. Lets say you just want to open a window containing Yahoo using a form button:

<form>
<input type="button" value="Click here to see" onclick="window.open('http://www.yahoo.com')" />
</form> 

The above button merely opens an ordinary looking new window. However, where JavaScript shines when it comes to manipulating windows is the ability to customize the look of them, whether it's the windows' dimensions or look.