Webmaster Resources Center

Welcome to the Bravenet Resource Center. Use these resources to help make your web pages more advanced and fun to use.

Articles & Tutorials

Open Links in a New Window

by Jocelyn Kinnear


Summary : Here is a valid way to open links in a new window using JavaScript. This is easy to use and customize.

Here is an easy way to open a browser in a new window with JavaScript. You might find it convenient to use something like the "target" attribute; however, this attribute is deprecated and shouldn't be used. Unlike the target attribute, you can specify the width and height of the window you are opening using the following method.

<a href="javascript:void(0)" onclick="window.open('http://website.com','Bravenet.com', 'width=200,height=200')">
Open a New Window
</a>

Customize the Script for Your Site:


  1. In the code above, you will notice that there is a URI defined as http://www.bravenet.com. Replace that URI with the address of the page that you would like to open.
  2. You will notice width=200. Replace "200" with the width size, in pixels, that you would like the new window to be.
  3. height=200 As with the width, you can set the height of the new window here by replacing the "200" with your desired height.
  4. Replace "Open a New Window" with the text that you would like your visitors to click on in order to open the new window.

Once the code is edited, you can place it anywhere in the body of your webpage. This code can be very helpful if you want to open a small window for something such as an image gallery.