How To Use The To Make Links & Open Them Where You Want! »
Có thể bạn quan tâm
Contents
- 1 Code Example
- 2 Frames deprecated; only use _blank
- 3 Default target
- 4 a target=”_blank” Open in New Browser Tab (or Window)
- 4.1 Why Open in a New Browser?
- 4.2 Open All External Links in a New Tab with JavaScript
- 4.3 Reasons not to use `target=”_blank”
- 5 Values of the target Attribute
- 6 All Attributes of the anchor Element
- 7 Browser Support for target
Code Example
<a href="/" target="_blank">The home page will open in another tab.</a>The home page will open in another tab.Frames deprecated; only use _blank
The only currently relevant value of target is _blank. The other values of target were used to specify specific frames. However, frames have been deprecated in HTML5.
Default target
If no target is specified, the link will open in the current context, unless the user or browser specifies otherwise.
a target=”_blank” Open in New Browser Tab (or Window)
The target attribute specifies where the linked document will open when the link is clicked. The default is the current window. If target="_blank", the linked document will open in a new tab or (on older browsers) a new window.
Why Open in a New Browser?
The most common reason to use `target=”_blank” is so that offsite links open in a separate tab. This allows a user to click on a reference and come back to it later without leaving the current page. It keeps visitors on your site longer and improves most of your metrics: bounce rate, conversion, pages visited.
Open All External Links in a New Tab with JavaScript
You don’t need to manually add target="_blank" to every link on your site. If you link out a lot (which you should do), it is easy to add some JavaScript code to your site and turn all external links into _blank links automatically.
jQuery(document.links) .filter(function() { return this.hostname != window.location.hostname; }) .attr('target', '_blank');(You can see a slightly modified form of this code in action on every page of this website.) This trick requires jQuery, but there is a good chance you are using it already. It is used in the most popular frameworks and content management systems, including WordPress, Drupal, and Twitter Bootstrap. If you need to do it without jQuery, that can be done as well. Here is a “plain JavaScript” version:
function externalLinks() { for(var c = document.getElementsByTagName("a"), a = 0;a < c.length;a++) { var b = c[a]; b.getAttribute("href") && b.hostname !== location.hostname && (b.target = "_blank") } } ; externalLinks();Besides making it easier, this cleans up your markup considerably.
Reasons not to use `target=”_blank”
Some people argue that users do not prefer to open links in a new browsing context. They think that doing so is similar to popup ads and other annoying behavior. With the rise of tabbed browsing, this argument has largely gone away. Most users prefer to open links in a new tab, because it allows them to come queue referenced links for later reading without losing their current browsing context.
Values of the target Attribute
| Value Name | Notes |
|---|---|
| _blank | Opens the linked document in a new tab or window. |
| _parent | Opens the link in the parent frame. Frames are deprecated in HTML5. |
| _self | Open the link in the current frame. |
| _top | Opens the link in the top-most frame. Frames are deprecated in HTML5. |
| frame name | Opens the link in the named frame. Frames are deprecated in HTML5. |
All Attributes of the anchor Element
| Attribute name | Values | Notes |
|---|---|---|
| hreflang | Specifies the language of the linked resource. | |
| download | Directs the browser to download the linked resource rather than opening it. | |
| target | _blank _parent _self _top frame name | Specifies the context in which the linked resource will open. |
| title | text | Defines the title of a link, which appears to the user as a tooltip. |
| href | url | Specifies the linked document, resource, or location. |
| name |
Browser Support for target
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| All | All | All | All | All | All |
Từ khóa » Html5 A Tag Target
-
HTML A Target Attribute - W3Schools
-
: The Anchor Element - HTML: HyperText Markup Language | MDN
-
When To Use Target="_blank" | CSS-Tricks
-
The A Target HTML Attribute Explained - FreeCodeCamp
-
HTML | Target Attribute - GeeksforGeeks
-
Is It Alright To Use Target="_blank" In HTML5? - Stack Overflow
-
Don't Use The Target="_Blank" Link Attribute In These Cases
-
What Is The HTML Target Attribute?
-
A – Hyperlink (CHANGED) - HTML5 - W3C On GitHub
-
In This Section, We Will See The Use Of Target Attribute Of Anchor Tag In ...
-
HTML Tutorial => Target Attribute In Form Tag
-
The Target Attribute Of Anchor Tag In HTML - HTML Tutorial 35
-
HTML Link Target Attribute
-
Target Attribute Reference For Anchor Tags In HTML - DigitalOcean





