How To Open Html Page In New Window

Tabs are nifty, aren't they? They allow the multitasker in all of us to juggle a bunch of online tasks at the same time.
Tabs are so common now that, when yous click on a link, it's probable information technology'll open in a new tab.
If you've ever wondered how to do that with your own links, you lot've come up to the right place.
The Anchor Chemical element
To create a link on a web page, you lot need to wrap an element (text, a moving picture, and so on) in an anchor (<a>
) chemical element and set its href
aspect to the URL y'all want to link to.
<p>Check out <a href="https://www.freecodecamp.org/">freeCodeCamp</a>.</p>
Check out freeCodeCamp.
If you lot click on the link to a higher place, the browser volition open the link in the current window or tab. This is the default behavior in every browser.
To open a link in a new tab, nosotros'll need to look at some of the other attributes of the anchor element's other attributes.
The Target Attribute
This attribute tells the browser how to open the link.
To open up a link in a new tab, just gear up the target
aspect to _blank
:
<p>Bank check out <a href="https://www.freecodecamp.org/" target="_blank">freeCodeCamp</a>.</p>
Now when someone clicks on the link, it will open in a new tab, or possibly a new window depending on the person's browser settings.
Security concerns with target="_blank"
I strongly recommend that you always add rel="noreferrer noopener"
to the anchor element whenever yous use the target
attribute:
<p>Check out <a href="https://world wide web.freecodecamp.org/" target="_blank" rel="noopener noreferrer">freeCodeCamp</a>.</p>
This results in the following output:
Check out freeCodeCamp.
The rel
aspect sets the relationship between your page and the linked URL. Setting it to noopener noreferrer
is to forestall a blazon of phishing known as tabnabbing.
What is tabnabbing?
Tabnabbing, sometimes chosen contrary tabnabbing, is an exploit that uses the browser's default behavior with target="_blank"
to gain fractional access to your page through the window.object
API.
With tabnabbing, a page that you link to could cause your folio to redirect to a fake login folio. This would be hard for near users to notice because the focus would be on the tab that just opened – non the original tab with your folio.
Then when a person switches back to the tab with your folio, they would run into the fake login folio instead and might enter their login details.
If you're interested in learning more about how tabnabbing works and what bad actors can do with the exploit, bank check out Alex Yumashev's commodity and this one by OWASP.
If you'd like to encounter a prophylactic working example, check out this page and its GitHub repo for more than information about the exploit and the rel
aspect.
In summary
Information technology's easy to utilise HTML to open a link in a new tab. Y'all just need an anchor (<a>
) chemical element with three important attributes:
- The
href
aspect set to the URL of the folio yous want to link to - The
target
attribute set to_blank
, which tells the browser to open up the link in a new tab/window, depending on the browser's settings - The
rel
attribute fix tonoreferrer noopener
to forbid possible malicious attacks from the pages you link to
Again, here'south a full working instance:
<p>Cheque out <a href="https://www.freecodecamp.org/" target="_blank" rel="noopener noreferrer">freeCodeCamp</a>.</p>
Which results in the following output in the browser:
Check out freeCodeCamp.
Thank you again for reading. Happy coding.
Larn to code for complimentary. freeCodeCamp's open source curriculum has helped more than forty,000 people get jobs as developers. Become started
Source: https://www.freecodecamp.org/news/how-to-use-html-to-open-link-in-new-tab/
Posted by: caponesquiter.blogspot.com
0 Response to "How To Open Html Page In New Window"
Post a Comment