Two actions on the same button

Asked

Viewed 474 times

1

Guys, I need help with something simple, but I couldn’t find it on the internet, maybe because I don’t know the correct term to search. But I wanted the following: When you click on the code button below, the first click will open a link, and the second click will open the second link. In short, two links on the same button. Currently my button is like this, but I wanted to make him open another link before opening the www.google.com link. Could someone help me with this?

<div class="baixar">
    <a id="botao2" href="www.google.com" target="_blank"><h3>DOWNLOAD</h3> </a>           
</div>

2 answers

3

Can change the href from the link after the first click, all within the attribute onclick:

<a id="botao2" href="http://primeirolink.com" target="_blank"
onclick="var t=this; setTimeout(function(){t.href='http://www.google.com'},10)">
   <h3>DOWNLOAD</h3>
</a>           

Clicking on the link will open the URL http://primeirolink.com and the attribute href will change to http://www.google.com. Clicking again will open http://www.google.com.

The setTimeout is to give a small delay so that the attribute is changed only after the click.

  • Man, I’m trying like this;<a id="botao2" href="http://primeirolink.com" target="_blank" onclick="var t=this; setTimeout(function(){t.href="<?php echo base64_decode($queryString["src"])?>"},10)> <h3>DOWNLOAD</h3> </a> But you don’t change the link, you keep going to the first link.

  • Look at the source code of the page to see how the HTML of the link is getting.

  • Failed to close the onclick with " after the ,10).

  • I put: http://prntscr.com/oll273. But it still doesn’t work :/

  • It is after the ,10), thus: <a id="botao2" href="http://primeirolink.com" target="_blank" onclick="var t=this; setTimeout(function(){t.href='<?php echo base64_decode($queryString["src"])?>'},10)"> <h3>DOWNLOAD</h3> </a>

  • And the link should be in single quotes. You put the PHP code inside double quotes, unlike what I put in the answer.

  • Ah, now it’s worked out. Thank you so much, man. You’re wild!

Show 2 more comments

-2

That’s a cool question! type ai click the button for the first time let’s say it opens the github and the second time the stack

come on

  • php
$link_count = 0
function AlternaLinks(){
    if ($link_count == 0){
        // manda para o primeiro link
        $link_count = 1
    } else {
        // manda para o segundo link
        $link_count == 0
   }
}

So it gets opened by clicking the first link and the click again will open the second and so infinitely

I hope I’ve helped

Browser other questions tagged

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