Opening A New Window Javascript Open Command
Today one of my PHP readers asked which was the best language to use to open a new pop-up window. She was trying to decide between PHP and Javascript. Most programmers feel that the best language to use for this task is Javascript. Why? Javascript is a client-side language. This means that the Javascript code is processed on the client-side by the web browser and the server does not need to process the code at all. PHP is a server-side language. The PHP code is processed by the server and then the resulting HTML (that creates the web page) is sent to the web browser. Because the code must first be processed on the server, the response time is slower. Most programmers feel that a simple task such as opening a pop-up window is best accomplished using a client-side language such as HTML or Javascript. How? HTML Target Attribute You can use the HTML anchor tag and the target attribute to open a new window. However, the target attribute is being phased out. In spite of this, the HTML method is still popular. Here is the code. The attribute/value pair of target="_blank" is what causes the newpage.html to open in a new window.
Javascript – Open Command Why is Javascript the favorite method for opening a new pop-up window? Because it allows you to have more control over the parameters for the new window. In the example below, we have set the width and height of the new window to be 400 pixels each. This is done using the features parameter.
As you can see, the Javascript code is placed between the opening <script> and closing </script> tags.
The open command has four optional parameters that you can use to control the new window. Each parameter is placed between single quotes and the parameters are separated by a comma. All of the parameters are grouped together between opening and closing parenthesis. We will discuss the three parameters that are used most often. URL Parameter The url parameter sets the url address for the web page that will be loaded into the new pop-up window. Name Parameter The name parameter gives the pop-up window an ID name. You can use anything here that you want from example to Sam. Features Parameter In the example above, we set the width and height features to 400 pixels each. You will also notice that these features are placed together between single quotes. Each feature is followed by an equal sign. After the equal sign is the value for that feature. Each feature/value pair is separated by a comma only (NO spaces). The config= in front of the 'group of features' is optional. Besides the width and height, there are many more features that you can use to control the new window. The width and height features are set in pixels but the other features are set to yes or no. You can also use 1 for yes or 0 for no. The value of yes will cause the element of be placed on the web page. Of course if the value is no, the element is left off of the page. The chart below summarizes the most popular features.
| |||||||||||||||||||||||||||||||||
This site needs an editor - click to learn more!
Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map
Content copyright © 2023 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact
BellaOnline Administration
for details.