How to open link in new tab on html?

后端 未结 10 1894
孤独总比滥情好
孤独总比滥情好 2020-11-22 11:57

I\'m working on an HTML project, and I can\'t find out how to open a link in a new tab without javascript.

I already know that

相关标签:
10条回答
  • 2020-11-22 12:25

    target="_blank" attribute will do the job. Just don't forget to add rel="noopener noreferrer" to solve the potential vulnerability. More on that here: https://dev.to/ben/the-targetblank-vulnerability-by-example

    <a href="https://www.google.com/" target="_blank" rel="noopener noreferrer">Searcher</a>
    
    0 讨论(0)
  • 2020-11-22 12:26

    You can use:

    <a href="http://www.WEBSITE_NAME.com"  target="_blank"> Website</a>
    

    However the above make your site vulnerable to phishing attacks. You can prevent it from happening in some browsers by adding rel="noopener noreferrer" to your link. With this added, the above example becomes:

    <a href="http://www.WEBSITE_NAME.com" rel="noopener noreferrer" target="_blank">Website.com</a> 
    

    check out for more information: https://www.thesitewizard.com/html-tutorial/open-links-in-new-window-or-tab.shtml

    0 讨论(0)
  • 2020-11-22 12:28

    The simple way to open the link in a new tab is to add a target attribute in the link having a value equals to "_blanl", like this :

    <a href="http://www.WEBSITE_NAME.com" target="_blank"></a>

    0 讨论(0)
  • 2020-11-22 12:29

    When to use target='_blank' :

    The HTML version (Some devices not support it):

    <a href="http://chriscoyier.net" target="_blank">This link will open in new window/tab</a>
    

    The JavaScript version for all Devices :

    The use of rel="external" is perfectly valid

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript">
        $('a[rel="external"]').attr('target', '_blank');
    </script>
    

    and for Jquery can try with the below one:

    $("#content a[href^='http://']").attr("target","_blank");
    

    If browser setting don't allow you to open in new windows :

    href = "google.com";
    onclick="window.open (this.href, ''); return false";
    
    0 讨论(0)
  • 2020-11-22 12:38

    Use target="_blank":

    <a href="http://www.example.com/" target="_blank" rel="noopener noreferrer">This will open in a new window!</a>
    
    0 讨论(0)
  • 2020-11-22 12:39

    If you would like to make the command once for your entire site, instead of having to do it after every link. Try this place within the Head of your web site and bingo.

    <head>
    <title>your text</title>
    <base target="_blank" rel="noopener noreferrer">
    </head>
    

    hope this helps

    0 讨论(0)
提交回复
热议问题