link does not open in html

1

I'm developing a Chrome extension in which I'd like to open a link. For this, I use the following line:

<p><a href="https://www.youtube.com/" onclick="window.open(href)">Y</a>

I do not know much about this language and I do not know why it does not work, since in the tutorials I've seen it was done that way. I have tried to put other links and the result has been the same.

    
asked by pepito 30.06.2017 в 08:01
source

2 answers

3

The anchor element of HTML, representing the <a> tag, supports the following attributes:

  • href
  • hreflang
  • referrerpolicy
  • rel
  • target
  • type
  • download (as of HTML5)

As a curious fact, the title attribute, which is widely used, does not appear in the current documentation.

There are other obsolete attributes such as: charset

To see the use of each of these attributes, you can consult the MDN documentation , which exists in Spanish.

To create a link you can simply do:

<a href="https://www.youtube.com">YouTube</a>

And within the% co_of opening% you can place one or more of the labels mentioned above.

Example:

<p>Sin nada:</p>
<a href="https://www.youtube.com">YouTube</a><br />
<p>Con título, usando la etiqueta  <code>title</code> . Deja un  momento el puntero sobre el enlace:</p>
<a href="https://www.youtube.com" title="Ir a Yo tuve :)">YouTube</a>
<p>Abrir enlace en otra página, usando la etiqueta  <code>target</code>:</p>
<a href="https://www.youtube.com" title="Ir a Youtube :)" target="_blank">YouTube</a>

Regarding <a> the documentation says the following:

  

Frequently abuse of anchor tags with the   Use of onclick events to create pseudo-buttons by adjusting onclick   a " href " or " # " to prevent page reload.   These values cause unexpected behavior with links from   copied / drawn, opening links in new tabs / windows,   the saved of links (bookmarking), and when JavaScript is still   downloading, this throws errors, or is disabled. This too   leads to incorrect semantics for technologies of   assistance (eg, screen readers). In these cases,   recommends using a javascript:void(0) instead. In general, you should only   use an anchor for navigation using a URL   adequate.

It should also be noted that the <button> tag is not used only for links to external web pages using the <a> protocol, but also for links on the same page using http , as well as links to #seccion addresses , to addresses of ftp , to images, to telephone numbers. All this is detailed in the documentation (link above).

    
answered by 30.06.2017 / 08:42
source
1

With this simply:

<p><a href="https://www.youtube.com/">Texto del enlace</a><p>

I would open the youtube page, for this case.

If you want to open it in a new window, it would be this other case:

<p><a href="https://www.youtube.com/" target="_blank">Texto del enlace</a></p>

The onclick attribute is just in case you want to add another type of functionality, through ajax, javascript, ..

    
answered by 30.06.2017 в 08:35