HTML link not going to external site

3k views Asked by At

I have been running a localhost website with react.js while I am building a website and when I am trying to link to an external site (e.g. youtube) it ends up going to a link like this:

http://localhost:3000/www.youtube.com

while I am trying to go to:

https://www.youtube.com

I am using this to get my link:

<a href='youtube.com' target='_blank' rel='noreferrer'>YouTube</a>
3

There are 3 answers

0
Lakshmanan k On BEST ANSWER

You need to specify the protocol, or put // at the start of the href attribute. For example: Try using a protocol like http:// or // to external links like this :

 <a href='https://youtube.com' target='_blank' rel='noreferrer'>YouTube</a>

See this good answer on SO : https://stackoverflow.com/a/8951636/6028607

0
zahl On

Try this: <a href='https://youtube.com' target='_blank' rel='noreferrer'>YouTube</a>

0
madaraUchiha On

It's easy to use HTML to open a link in a new tab. You just need an anchor () element with three important attributes:

  1. The href attribute set to the URL of the page you want to link to.
  2. The targetattribute set to _blank, which tells the browser to open the link in a new tab/window, depending on the browser's settings.
  3. The rel attribute set to noreferrer noopener to prevent possible malicious attacks from the pages you link to

try using this

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