Monday, December 28, 2009

Open a link in a new window or in a new tab using HTML Target

The <a> tag defines an anchor. An anchor is used in a HTML document in order to create a link to another document, by using the href attribute.

Note that by default anchor tag shows following behaviour,
- An unvisited link is underlined and blue
- A visited link is underlined and purple
- An active link is underlined and red.

Following is an example of an anchor link.
<a> href=
http://arjudba.blogspot.com/2009/11/affordable-search-engine-optimization.html>SEO packages
</a>
which will look like,
SEO packages

The named anchor itself doesn't have a hash mark. If you want to point to a certain part of a webpage you have to specify id of that document and then link to the named anchor with a hash mark. For example if we want to point to platinum package in the same post then we have to specify as,
<a> href=
http://arjudba.blogspot.com/2009/11/affordable-search-engine-optimization.html#platinum>Platinum Package
</a>
which will look like,
Platinum Package

If you left click on these two hyper link you will see that both links are opened in the same window. But after clicking the link sometimes it may be useful to open window in a new window or in a new tab so that user don't leave the current window. We can achieve this by using TARGET.

Clicking on a link simply loads a new document in the same window where the link was. The TARGET keyword of anchor controls where the new document will be displayed when the user follows a link. With TARGET keyword, you can have the new document open in a new window, or if you are using frames, in another frame.

TARGET can have four predefined values.
1) "_blank"
2) "_parent"
3) "_self"
4) "_top"
Note that each value start with an underscore and are lowercase.

1)TARGET = "_blank": If you use TARGET="_blank" with the anchor tag then the new document opens in a new window while leaving the main window. Following is an example,
<a> href=
http://arjudba.blogspot.com/2009/11/affordable-search-engine-optimization.html#platinum TARGET="_blank">Platinum Package
</a>
which behaves as,
Platinum Package

2)TARGET = "_parent": "_parent" is used in the situation where a frameset is nested inside another frameset. In that case you have both parent frameset and child frameset existed. By using TARGET=_parent causes a link in one of the child frameset documents uses "_parent" to load the new document.
If the current document's frameset file does not have any "parent", then "_parent" works exactly like "_top": the new document is loaded in the full window.

3)TARGET = "_self": TARGET="_self" puts the new document in the same window and frame as the current document. "_self" works the same as if you had not used TARGET at all.

4)TARGET = "_top": TARGET = "_top" loads the linked document in the topmost frame which means, the new page fills the entire window.

Another use of TARGET is TARGET = window name by which window name is used to put the linked document in a frame or window other than the frame the link is in.

Related Documents

No comments:

Post a Comment