You are here: Home » All Posts » JavaScript Popup Windows » Using the method

Using the method

in JavaScript Popup Windows

The syntax of the method is given below:
open (URL, windowName[, windowFeatures])

The URL of the page to open in the new window. This argument could be blank.

A name to be given to the new window. The name can be used to refer this window again.

A string that determines the various window features to be included in the popup window (like status bar, address bar etc)

The following code opens a new browser window with standard features. ("","mywindow"); 

Changing the features of the Popup

You can control the features of the popup using the last argument to the method. The following code opens a window with a status bar and no extra features. ("","mywindow","status=1");

The code below opens a window with toolbar and status bar. ("", "mywindow","status=1,toolbar=1");

The table shows the features and the string tokens you can use:

status The status bar at the bottom of the window.
toolbar The standard browser toolbar, with buttons such as Back and Forward.
location The Location entry field where you enter the URL.
menubar The menu bar of the window
directories The standard browser directory buttons, such as What’s New and What’s Cool
resizable Allow/Disallow the user to resize the window.
scrollbars Enable the scrollbars if the document is bigger than the window
height Specifies the height of the window in pixels. (example: height=’350′)
width Specifies the width of the window in pixels.


The following code opens a window with menu bar. The window is re-sizable and is having 350 pixels width and 250 pixels height. ("","mywindow","menubar=1,resizable=1,width=350,height=250");

Example 1

A window with location bar, status bar, scroll bar and of size 100 X 100 ("", "mywindow","location=1,status=1,scrollbars=1, width=100,height=100");

Example 2

Moving the window to a desired location

You can use the window.moveTo function to move the popup window to a desired location.
The code below shows positioning the popup at a desired location.

function mypopup()
    mywindow ="", "mywindow", "location=1,status=1,scrollbars=1,  width=100,height=100");
    mywindow.moveTo(0, 0);

The code positions the popup on the top left corner of the screen.

Putting it all together

Now we will combine all these information to create the popup windows of different types.
The Code below opens a popup window when you enter the page:

 <title>JavaScript Popup Example 3</title>
<script type="text/javascript">
function poponload()
    testwindow ="", "mywindow", "location=1,status=1,scrollbars=1,width=100,height=100");
    testwindow.moveTo(0, 0);
<body onload="javascript: poponload()">
<h1>JavaScript Popup Example 3</h1>

Notice that the URL is kept blank. This will open a blank window. You can see the code in work in this file:
JavaScript Popup Example 3

Popup On Exit

The following code pops up a window when the user exits a page.

 <title>JavaScript Popup Example 3</title>

<script type="text/javascript">
function exitpop()
    my_window ="", "mywindow1", "status=1,width=350,height=150");
    my_window.document.write('<h1>Popup Test!</h1>');

<body onunload="javascript: exitpop()" >
<h1>JavaScript Popup Example 4</h1>

The code contains an extra line:

my_window.document.write('<h1>Popup Test!</h1>') 

This code displays a line ‘Popup Test!’ in the popup.

The code is available in the file:
JavaScript Popup Example 4

Be Sociable, Share!

{ 93 comments… read them below or add one }

Vietnam Travel Blog March 26, 2012 at 8:48 am

Nice article, but how to open a new tab window with different url from href params?


Amit March 20, 2012 at 6:20 pm


I tried using the code in example 3; nothing happening. I am struck. please help.


Get Smart March 5, 2012 at 6:42 pm

This works perfectly. I just want to change it so that it opens in the same window and we are golden. Thanks.


tushar lapani March 2, 2012 at 4:59 pm

i want to open new window in same/parent window by using method.
If use method with only one parameter (link of new window) then it works correctly. But when i pass second parameter “_parent” within it displays msg like “file not found”.
can i use this target value(_parent) as a second parameter. If yes then what is prob with my code.
my code is like ——‘mypage.html’,’_self’);

what is prob with this???????
can anyone help me plz


abdul mobeen February 21, 2012 at 7:46 am

hey Racsh;
so you want to open ur desired site in pop-down window :)))… e.g u want to open google in newly poped up window..try this…

function openMe(){
var newWinAttrs = ‘resizable=no, scrollbars=no, status=yes, height=420, width=600 ‘;
var myNewWin =“”,”My new window”, newWinAttrs);

myNewWin.document.write(‘Wait google is opening…..’);
//change the site to what u like to open




Muhsinath March 12, 2012 at 5:40 am

Thank you


BmtJedi February 17, 2012 at 11:15 pm

This works perfectly. I just want to change it so that it opens in the same window and we are golden. Thanks.


Quang February 7, 2012 at 11:57 pm

I tried and doesn’t work well in document ready.

Thanks for great article.


berk February 7, 2012 at 12:04 pm


this code is not compatible with blogspot (blogger) blogs. how can i adapt this code to blogger tamplate?



jemima chella February 1, 2012 at 8:59 am

how to open a file in the browser using command in jsp??pls i need a reply soon


Argha January 24, 2012 at 7:43 am

how to open a popup always in IE.
reply pls.


anil kumar February 10, 2012 at 1:09 pm

hello Argha

function poponload()
{“”, “mywindow”, “location=1,status=1,scrollbars=1,width=200,height=200″);
window.moveTo(20, 20);

This the JavaScript Popup Example


Racsh January 23, 2012 at 2:26 am

This is great but I need something like this, when you open a website there will be a new window will appear that link to a different website..Please help me guys.


Leave a Comment

Previous post:

Next post: