1

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>
Luke C
  • 39
  • 8
  • 1
    `'youtube.com'` by itself is a relative URL. It works when you type it into your browser's address bar, but in HTML it is interpreted as relative to the site and directory you are currently visiting. The simple solution is to specify it is an absolute URL by putting `https://` (or `http://` or even just `//`) at the start of the URL. – Liftoff Feb 03 '22 at 05:56
  • Does this answer your question? [html - links without http protocol](https://stackoverflow.com/questions/8951423/html-links-without-http-protocol) – Ivar Jan 15 '23 at 10:45

3 Answers3

1

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

Lakshmanan k
  • 122
  • 7
0

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

New Programmer
  • 108
  • 1
  • 1
  • 9
0

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>
madaraUchiha
  • 41
  • 1
  • 8