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:
- ‘url to open’
This is the web address of the page you wish to appear in the new window. - ‘window name’
You can give a name to your window. - ‘attribute1,attribute2′
A list of attributes.
Here are the attributes you can use for customizing your page:
- width=800
Use this to define the width of the new window. - height=600
Use this to define the height of the new window. - resizable=yes or no
Set this attribute whether the user may resize or not the window. - scrollbars=yes or no
This lets you decide whether or not to have scrollbars on the window. - 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.). - location=yes or no
Whether or not you wish to show the location box with the current url (The place to type http://address). - directories=yes or no
Whether you want or not to show extra buttons. - status=yes or no
Whether you want or not to show the window status bar at the bottom of the window. - menubar=yes or no
Whether you want or not to show menus at the top of the window (File, Edit, etc…). - 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
 

RSS/XML