Parameter target in HTML
By default, if you click on a link a document opens in the current window or frame. If necessary, this can be changed by setting parameter target in the a tag. This parameter can have the following values:
- _blank - loads the page in a new browser window;
- _self - loads the page in the current window;
- _parent - loads the page in the parent frame;
- _top - closes all frames and loads the page in a full browser window.
Example 1 shows how to create a link to a website that opens in a new window.
Example 1. Opening document in a new window.
<a href="http://www.google.com" target="_blank">Link opens a new window to site www.google.com</a>
If a site uses frames, then you can use the name of the frame as target's value (example 2).
Example 2. Opening document in a frame.
<a href="http://www.google.com" target="newframe">site www.google.com</a>
The link in the example 2 opens site www.google.com, which in turn opens in a frame with the name "newframe".
Note: if the parameter target has unknown value, for example, name of the frame has an error, then this causes the link to open a new window.
If you need to set your web page, to open all links in a new window, then there is no need to add to every tag a parameter
target="_blank". The code can be reduced if in the beginning of the page you add string
<base target="_blank">, as shown in example 3.
Example 3. Using the tag base.
<base target="_blank"> <a href="1.php">Link will open in a new window</a> <a href="2.php" target="_self">Link will open in the current window</a>
In order for the link to open in the current window, add the tag a with the parameter
target="_self", as shown in this example.