DEV Community

Cover image for Secure way to open an external link in a new tab or window
Hardique Dasore
Hardique Dasore

Posted on • Edited on

1 1

Secure way to open an external link in a new tab or window

In order to open a link from your website, we need to use the anchor tag <a> in HTML.
Inside the anchor tag the URL is added to the href parameter.



<a href="https://www.google.com/" >Google</a>


Enter fullscreen mode Exit fullscreen mode

Now to open the link in a separate tab, we add target="_blank" but this makes the website vulnerable to phishing attacks.



<a href="https://www.google.com/"  target="_blank">Google</a>


Enter fullscreen mode Exit fullscreen mode

How to prevent phishing attacks?

Opening an external link in a new tab makes your website vulnerable. The site you link can gain access to the window containing your website and can change it to display different webpage. This is called phishing. In order to make your website secure from tabnabbing, we add rel="noopener noreferrer"



<a href="https://www.google.com/" rel="noopener noreferrer" target="_blank">Google</a>


Enter fullscreen mode Exit fullscreen mode

Happy Coding!

Image description

Follow us on Instagram

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay