Open a new window with JavaScript

January 28, 2008

If you want to open a new window when clicking on a link you have to use a javascript function. Here is all you need:

window.open('url to open','window name','attribute1,attribute2')

Using this function you will be able to open a new browser window for the viewer to use. Here are some comments:

  1. ‘url to open’
    This is the web address of the page you wish to appear in the new window.
  2. ‘window name’
    You can give a name to your window.
  3. ‘attribute1,attribute2′
    A list of attributes.

Here are the attributes you can use for customizing your page:

  1. width=800
    Use this to define the width of the new window.
  2. height=600
    Use this to define the height of the new window.
  3. resizable=yes or no
    Set this attribute whether the user may resize or not the window.
  4. scrollbars=yes or no
    This lets you decide whether or not to have scrollbars on the window.
  5. toolbar=yes or no
    Whether or not the new window should have the browser navigation bar at the top (The back, foward, stop buttons..etc.).
  6. location=yes or no
    Whether or not you wish to show the location box with the current url (The place to type http://address).
  7. directories=yes or no
    Whether you want or not to show extra buttons.
  8. status=yes or no
    Whether you want or not to show the window status bar at the bottom of the window.
  9. menubar=yes or no
    Whether you want or not to show menus at the top of the window (File, Edit, etc…).
  10. copyhistory=yes or no
    Whether you want or not to copy the old browser window’s history list to the new window.

Here is an example of the javascript code:

function load() {var load = window.open('http://www.assistprogramming.com','','scrollbars=yes,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');}

Now create a link to open your new window like this:

<a href="javascript:load()">Open Window</a>

Click on the below link to see the effect:

Open Window

 

Post a comment

Name (required)

Mail (will not be published) (required)

Website

*
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word