Open a new window using Javascript


JavaScript : window.open

There are few times we would like top open a pop window to show some data or also be user interactive bu showing a good form in a pop window, window.open can be used for this pupose

We can directly write window.open(url) in the anchor tag, but let be more innovative and give more flexibility to our code, so we write a wrapper function around it.

The below example provides a broader view:

/* Function : New Window
|
| Description : This parameter defines how you want the new window to appear.
| This parameter is ignored if an existing window is to be reused.
| The contents of this parameter is a comma separated list of sub-parameters.
|
| Arguments :-
|
| left : yes or no
| specifies the recommended distance from the left of the
| screen to the left of the new window.
| top : yes or no
| specifies the recommended distance from the top of the
| screen to the top of the new window.
| width : yes or no
| specifies the width of the content area for the new window
| (including any scrollbars etc). |
| Note. IE7 will not allow you to set width below 250px.
| height : specifies the height of the content area for the new window
| (including any scrollbars etc).
| Note. IE7 will not allow you to set height below 150px.
| menubar : can be set to yes or no to indicate whether or not the new window
| should display a menubar.
| toolbar : can be set to yes or no to indicate whether or not the new window
| should display a toolbar.
| location : can be set to yes or no to indicate whether or not the new window
| should display the location |
| status : can be set to yes or no to indicate whether or not the new window
| should display the status bar.
| resizable : can be set to yes or no to indicate whether or not the new window can be resized.
| scrollbars : can be set to yes or no to indicate whether or not the new window
| should display scrollbars if required.
|
| Optional :-
|
| replace : This parameter defines how an existing window is to be reused.
| If true then the new page replaces the current page in the browser history.
| If false the new page is added to the browser history.
|
| Example: window.open(“URL”,”width=350, height=400, toolbar=no, resize=yes, scrollbars=yes, status=no, menubar=yes”);
|
| @access public
| @param string
| @param int
| @param int
| @return void
*/
function new_window(url,swidth,sheight)
{

var width = (swidth) ? swidth: 600;
var height = (sheight) ? sheight: 500;

if(url != “”)
window.open(url,”new_window”,”toolbar=no, width=”+width+”, height=”+height+”, status=no,scrollbars=yes, resize=yes, menubar=no”);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s