Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it valid to use custom name in "target" attribute of <a> tag?

I have code something like this:

<a href="http://google.com" target="_blank">google</a>
<a href="http://gmail.com" target="_blank">gmail</a>

Whenever I click one of the links, a new window or tab is created. I wanted the links to just use one.

So I changed my code like this:

<a href="http://google.com" target="google">google</a>
<a href="http://gmail.com" target="google">gmail</a>

It worked! It makes a new window just the first time either link is clicked, and after that clicks on the links appear in that window.

I think this is good, but I cannot find something about this in the W3C HTML 4 Spec. Is it valid and cross-browser compatible?

like image 998
Sanghyun Lee Avatar asked Nov 03 '11 04:11

Sanghyun Lee


People also ask

What is the use of target attribute in a tag?

Definition and Usage The target attribute specifies a name or a keyword that indicates where to display the response that is received after submitting the form. The target attribute defines a name of, or keyword for, a browsing context (e.g. tab, window, or inline frame).

What are three options for the target attribute?

_blank: It opens the link in a new window. _self: It is the default value. It opens the linked document in the same frame. _parent: It opens the linked document in the parent frameset.

Which are the valid HTML anchor tags?

The <a> nchor element is simply an anchor to or from some content. Originally the HTML specification allowed for named anchors ( <a name="foo"> ) and linked anchors ( <a href="#foo"> ).


2 Answers

Yes, that's exactly how you would use it in this instance. The value of the target attribute specifies where to open the linked document and can be one of _blank, _self, _parent, _top, or framename, where framename would be the name of the frame or window to use.

like image 116
animuson Avatar answered Oct 16 '22 02:10

animuson


Yes, that is perfectly valid and browser-compatible. The target specifies the name of the target window (or frame), which will be opened when it does not already exist.

The following have special meanings: _self, _blank, _parent, _top

Maybe you need a better HTML reference.

like image 24
Thilo Avatar answered Oct 16 '22 04:10

Thilo