How to open a popup window?

Hello, friends today we will learn how to open a new popup window using javascript. To open a new window by clicking on the button/any link, we will need to use the window. open method of javascript.

code of a popup window

By using the above code now we can open a new simple window, also this function can have different features of that window to appear.

Syntax[URL of the page], [Window Name], [Feature List], [Replace]);

Feature List:

PropertyDefault valueDescription
HeightautoHeight of the new window in pixels
WidthautoWidth of the new window in pixels
TopautoTop position new window
LeftautoLeft position new window
Address barnoAn address bar to be shown or not?
ResizablenoWhether a window can be resized or not.
MenubarnoPresence of the menu bar
ToolbarnoToolbar to be visible or not.
Scroll barsnoScroll bar to be visible or not.
StatusnoStatus bar to be visible or not.

Code for a full-screen pop-up window

Only Internet Explorer browser supports the fullscreen parameter.

So, if we need to open the fullscreen popup window in all browsers then we will use below modified function:

Below Code for all browsers fullscreen popup window

Code for a centered popup window

If we wan to open a new popup window in the center of the screen, then we should have the size of the window and the resolution of the screen. On the basis of available data, we can calculate the values of the top-left corner.

Centered popup window

About the author

Dinesh Sharma

I have worked on many CMS & Frameworks of PHP & I love to share my knowledge of what I am learning every day.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.