Open popup window with open.window method

To open a new window by clicking on the link, you will need to use window.open method of javascript.

Sample of popup window

Click here for simple popup window

<a href="javascript: void(0)" 
onclick="window.open('popup.html',
'windowname1',
'width=200, height=77');
return false;"
>
Click here for simple popup window</a>

Now you can open a simple window, also this function can have different features of that window to appear.

Syntax

window.open([URL], [Window Name], [Feature List], [Replace]);

Feature List:

PropertyDefault valueDescription
widthautospecifies width of the new window in pixels
heightautoheight of the window in pixels
topautospecifies window position
leftautospecifies window position
directoriesnoshould the directories bar be shown? (Links bar)
locationnospecifies the presence of the location bar
resizablenospecifies whether the window can be resized.
menubarnospecifies the presence of the menu bar
toolbarnospecifies the presence of the toolbar
scrollbarsnospecifies the presence of the scrollbars
statusnospecifies the presence of the statusbar


Click here for specific popup window

<a href="javascript: void(0)" 
onclick="window.open('popup.html',
'windowname2',
'width=200, \
height=77, \
directories=no, \
location=no, \
menubar=no, \
resizable=no, \
scrollbars=1, \
status=no, \
toolbar=no');
return false;"
>
Click here for specific popup window</a>

Fullscreen popup window

The fullscreen parameter is supported only by Internet Exploer browser.

If you need to open fullscreen popup window in all browsers you need to use this modified function:

All browsers fullscreen popup window

<script type="text/javascript">
<!--
function popup(url)
{
params = 'width='+screen.width;
params += ', height='+screen.height;
params += ', top=0, left=0'
params += ', fullscreen=yes';

newwin=window.open(url,'windowname4', params);
if (window.focus) {newwin.focus()}
return false;
}
// -->

</script>

<a href="javascript: void(0)"
onclick="popup('popup.html')">
Fullscreen popup window</a>

Centered popup window

To open new popup window in the middle of the screen we should know the size of a window and resolution of the screen. On the basis of these data, we will calculate values for the top-left corner.

Centered popup window

<script type="text/javascript">
<!--
function popup(url)
{
var width = 300;
var height = 200;
var left = (screen.width - width)/2;
var top = (screen.height - height)/2;
var params = 'width='+width+', height='+height;
params += ', top='+top+', left='+left;
params += ', directories=no';
params += ', location=no';
params += ', menubar=no';
params += ', resizable=no';
params += ', scrollbars=no';
params += ', status=no';
params += ', toolbar=no';
newwin=window.open(url,'windowname5', params);
if (window.focus) {newwin.focus()}
return false;
}
// -->

</script>

<a href="javascript: void(0)"
onclick="popup('popup.html')">
Centered popup window</a>

Related Posts Plugin for WordPress, Blogger...