Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • HTML Anchor target Attribute

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 707
    Comment on it

    The target attribute is used in hyperlinks. It specifies the destination of the hyperlink.

    The target attribute is used to determine where to open/load the current link, whether on the same tab, next tab, new window or new frame.

    If we do not specify the attribute in the anchor tag then it will automatically load the link in same window and tab.


    Syntax:-

    <a target="_blank|_self|_parent|_top|framename">

     

    Following are the attribute values:-

    • _blank
    • _self
    • _parent
    • _top

    1. _blank:-

    The _blank attribute opens the link in new tab or in new window.

    The benefit of using ('target', '_blank') is that we can check the new link without leaving the current page.

    There is back button in _blank attribute.

    If we want to open all the links into new tab automatically, then here is the Javascript code for that:-

    jQuery(document.links)   .filter(function() {     return this.hostname != window.location.hostname;   })     .attr('target', '_blank');

     

    Syntax:-

    <a href="#" target="_blank">Open link in new tab</a>

     

    Here is the link to load link in new tab or window:-
     

    https://jsfiddle.net/L64czmw4/4/

     

    2. _self:-

    The target="_self" attribute opens the link in the same tab or window. It is default value for this attribute.

    Syntax:-

    <a href="http://www.yahoo.com" target="_self">Visit Yahoo</a>

     

    3. _parent:-

    The target="_parent" attribute opens the link in the parent or next level of frameset.

    This attribute is not used in HTML5.

    Syntax:-

    <a href="#" target="_parent">Open link</a>

     

    4. _top:-

    In this the currently displayed page is replaced by the new link page. But there is a back button available.


    Syntax_

    <a href="#" target="_top">Open link</a>

     

     

     

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: