JavaScript window.open() Open a new window and set properties

 window.open is the JavaScript standard syntax for opening new windows. Sometimes applications on web pages need to open a new window to display additional web page information. Through the window.open method, we can specify the opening of a new window Various specifications, such as width, height, whether to display the browser toolbar, whether to display the scrollbar... etc. In this introduction, we will introduce how to use JavaScript's window.open() to open a new window. The new window can display different HTML or PHP web pages.


JavaScript window.open open new window syntax
window.open('URL of the new window','Name of the new window', config='height=height,width=width');
The first parameter "new window URL" of window.open is a necessary item, which can be other pages of the website itself, or pages of other websites, and the third parameter config is used to set the width, height, and height of the new window. For the function settings of other windows, please refer to the config parameter table for common setting values.

window.open config common parameter list
parameterParameter value and description
toolbarSpecify whether to display the toolbar, the default is to display, if you want to set it to not display, the wording is toolbar=no.
scrollbarsSpecify whether to display scroll bars. To display the wording is scrollbars=yes, and not to display the wording is scrollbars=no.
resizableWhether visitors can adjust the window size by themselves, the default is yes, if you want to set it to not be adjustable, the wording is resizable=no.
locationWhether to display the address bar, the default is to display, if not to display, the wording is location=no.
menubarWhether to display the directory column, it will be displayed by default. If not, the wording is menubar=no.
statusWhether to display the status bar, the default is to display, if not to display, the wording is status=no.
leftThe distance from the left, in pixels.
topThe distance from the top, the unit is pixels.

JavaScript window.open example
<a href="#" onclick="window.open(' http://tw.yahoo.com','Yahoo', config='height=500,width=500');">Open a new window</a a>
The example output is asThe above is the application of window.open's config setting value. The example only uses the effect of setting width = 500px and height = 500px. You can also try to set different config values, such as adding no toolbars or no URL bars. With window.close, it is designed to be a new window with the function of closing after opening.

[2014.10.3] Errata modification, the scrollbars part of the config parameter table has been modified correctly, thanks to the netizen Milk for providing the correct information.

Post a Comment

0 Comments