How to do lidiv class="class" onclick="window.location = 'link';" / div open in new tab?

4

I'm trying to open a link in div in a new tab, but       target="_blank" is not working.

 Eu queria abrir o link numa nova aba.

<li>
    <div class="clientes" target="_blank" onclick="window.location='LINK';">
        TEXTO
    </div>
</li>

Could someone help me?

    
asked by anonymous 19.05.2017 / 16:41

4 answers

3

The target attribute is for anchors and does not work on elements div .

You should use <div><a target="_blank" href="o-teu-link.com">texto</a></div> which is the correct semantics. If you want to change the color you can use CSS.

Example:

.clientes a {
  text-decoration: none;
  color: darkgreen;
}
<div class="clientes"><a target="_blank" href="o-teu-link.com">texto A</a></div>
<div class="clientes"><a target="_blank" href="o-teu-link.com">texto B</a></div>
    
19.05.2017 / 16:54
3

You can use a tag to link to urls. To open in new tab:

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

But if for some reason you really need it to be this way, you can use:

<li>
    <div class="clientes" onclick=" window.open('http://google.com','_blank')">
        TEXTO
    </div>
</li>
    
19.05.2017 / 16:51
1

With the code that is in the question it is necessary to open the javascript page so the code stays.:

<li>
   <div class="clientes"  onclick="window.open('LINK');">text</div>
</li>

With the questions I think what you want is a tag that will look like this:

<li>
   <a target="_blank"  href="LINK">text</a>
</li>
    
19.05.2017 / 16:51
0

Thank you to all who responded. Sorry if I was a bit annoying, since I only know the basics of the basics. Thank you!

    
19.05.2017 / 17:10