How to open link in new tab on html?

后端 未结 10 1895
孤独总比滥情好
孤独总比滥情好 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:40

    You could do it like this:

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

    Originally was:

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

    Also look at the following url on MDN for more information about security and privacy:

    https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#Security_and_privacy

    which in turn has a link to a good article named Target="_blank" - the most underestimated vulnerability ever:

    https://www.jitbit.com/alexblog/256-targetblank---the-most-underestimated-vulnerability-ever/

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

    Set the 'target' attribute of the link to _blank:

    <a href="#" target="_blank" rel="noopener noreferrer">Link</a>
    

    Edit: for other examples, see here: http://www.w3schools.com/tags/att_a_target.asp

    (Note: I previously suggested blank instead of _blank because, if used, it'll open a new tab and then use the same tab if the link is clicked again. However, this is only because, as GolezTrol pointed out, it refers to the name a of a frame/window, which would be set and used when the link is pressed again to open it in the same tab).

    Security Consideration!

    The rel="noopener noreferrer" is to prevent the newly opened tab from being able to modify the original tab maliciously. For more information about this vulnerability see these resources:

    • https://dev.to/ben/the-targetblank-vulnerability-by-example
    • https://support.detectify.com/support/solutions/articles/48001048981-external-links-using-target-blank-
    0 讨论(0)
  • 2020-11-22 12:44

    Use one of these as per your requirements.

    Open the linked document in a new window or tab:

     <a href="xyz.html" target="_blank"> Link </a>
    

    Open the linked document in the same frame as it was clicked (this is default):

     <a href="xyz.html" target="_self"> Link </a>
    

    Open the linked document in the parent frame:

     <a href="xyz.html" target="_parent"> Link </a>
    

    Open the linked document in the full body of the window:

     <a href="xyz.html" target="_top"> Link </a>
    

    Open the linked document in a named frame:

     <a href="xyz.html" target="framename"> Link </a>
    

    See MDN

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

    If anyone is looking out for using it to apply on the react then you can follow the code pattern given below. You have to add extra property which is rel.

    <a href="mysite.com" target="_blank" rel="noopener noreferrer" >Click me to open in new Window</a>
    
    0 讨论(0)
提交回复
热议问题