HTML link does not open

2

Because I want eblace to open in the same tab, I have not added any target, since it is assumed that "_self" is the default one. However, only with this code, does not open any link:

<!DOCTYPE html>
<html>
  <head>
    <style type="text/css">
    body
    {
      min-width:360px;
    }
    a{
       color:#009900;
       text-decoration:none;
    }
    a:hover
    {
      text-decoration:underline;
    }
    h1
    {
      font:1.5em sans-serif;
      color:#fff;
      background:#006600;
      padding:5px
    }
    </style>
  </head>

  <body>
    <h1>Abre</h1>
    <a href="www.youtube.com" >YT</a>
  </body>
</html>

I have tried to put onclick="window.open(this.href)" after the link, but that has not solved the problem. I know the problem is not the link itself, since putting traget="_blank" opens. The problem is that in this way opens in another tab and I would like to do it in it. What can I do to make the link open and do it on the same tab?

    
asked by pepito 04.07.2017 в 09:11
source

1 answer

2

Add the http:// protocol to the link.

<!DOCTYPE html>
<html>
  <head>
    <style type="text/css">
    body
    {
      min-width:360px;
    }
    a{
       color:#009900;
       text-decoration:none;
    }
    a:hover
    {
      text-decoration:underline;
    }
    h1
    {
      font:1.5em sans-serif;
      color:#fff;
      background:#006600;
      padding:5px
    }
    </style>
  </head>

  <body>
    <h1>Abre</h1>
    <a href="https://www.youtube.com" >YT</a>
  </body>
</html>

We must add the protocol http or https because without it, the URL was working as a relative URL, attaching the string www.youtube.com to the URL that has the browser, so that if we are in < a href="http: // localhost"> link the result of the click was redirecting us to link

Adding the protocol if it takes us directly to link

    
answered by 04.07.2017 в 09:16