How to open link in a new tab?

Asked

Viewed 22,532 times

4

Follow the code below that I’m having difficulty using target="_Blank" how could I solve this.

<div class="opt" onCLick="location.href='#';">Txt</div>

THANK YOU VERY MUCH

  • 1

    Your element is a div and not a link, try to <a href="/link" target="_blank" />

  • 1

    https://answall.com/a/39691/57801. , https://answall.com/q/75901/57801 , https://answall.com/q/39620/57801 , https://answall.com/a/40576/57801

1 answer

8

If you really want to use a div to create a link, follow the example using Javascript:

<div class="opt" onCLick="window.open('https://www.google.com','_blank');">Txt</div>

Replace 'Location.href' with 'window.open', so you can do it define the 'target'.

If you want to make a simple link I recommend using the tag a:

<a href="https://www.google.com" target="_blank">Txt</a>
  • I didn’t want to lose the style I had applied to div and you helped a lot. Thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.