mddanishyusuf / dailyhack

🐱‍💻 Tiny Tiny Hacks we use in our daily life.
https://dailyhack.now.sh/
149 stars 15 forks source link

Open links in new tab safely #62

Open FabioRosado opened 5 years ago

FabioRosado commented 5 years ago

Everyone knows that if you use target="_blank" on a link tag that link will be open in a new tab. But using just this is a security risk and could allow bad people to take control of your page by abusing the window.opener event - read more about it here

So if you need a link to open on a new tab, make sure you add rel="noopener noreferrer" to the tag as well.

So instead of using:

<a href="http://example.com" target="_blank">Link</a>

You should use: <a href="http://example.com" target="_blank" rel="noopener noreferrer">Link</a>

mddanishyusuf commented 5 years ago

@FabioRosado this is really helpful. Thanks

radioblahaj commented 5 years ago

This is cool, Thanks!