HTML button go to link

Asked

Viewed 24,130 times

0

Hello, I’m a beginner and I would like to know how to redirect this button(Sign) to enable terms of use for some link.

<div class="modal-body">
     <!--botão termos de uso-->
     <script>   
         function HabiDsabi(){  
             if(document.getElementById('habi').checked == true){ 
                 document.getElementById('envia').disabled = ""  
             }  
             if(document.getElementById('habi').checked == false){ 
                 document.getElementById('envia').disabled = "disabled"  

            }
         }
     </script>
     <form name="form1">
         <p>
             <input type="checkbox" name="habi" id="habi" onClick="HabiDsabi()"> 
             Eu li e aceito os termos de uso 
             <a target="_blank" href="tos.html">termos de uso<a>.
         </p>
         <input type="button" class="btn btn-terciary"  name="envia" id="envia" value="Assinar" disabled>
     </form>
     <!-- fim do botão -->
</div>
  • 3

    If it is to redirect to another page, use the <a> with the attribute href.

  • From what I understand, you want to redirect the user to a link when they click the button and have checbox marked, correct? If so, within its Enable(){}function, when redirecting just use this function ( window.open( URL, name, Specs ) ) If so, for more information see: https://www.geeksforgeeks.org/open-a-link-without-clicking-on-itusing-javascript/

3 answers

2


You can create a function with the method window.location.href = "URLaSerRedirecionada"; and call this function in the click, or call the direct method with onclick;

<button onclick="window.location.href = 'http://answall.com'">link</button>

  • Where can I put '_Blank' to open in a new tab?

  • for Bir in another tab straight from the button you can use the window.open, example: <button onclick="window.open('http://answall.com');">link</button>

1

You can redirect using window.Location in onclick confome below:

function HabiDsabi() {
  if (document.getElementById('habi').checked == true) {
    document.getElementById('envia').disabled = ""
  }
  if (document.getElementById('habi').checked == false) {
    document.getElementById('envia').disabled = "disabled"
  }
}

function assinar(){
  window.location.href = "minhaNovaPagina.html"
}
<div class="modal-body">

<form name="form1">


<p>
    <input type="checkbox" name="habi" id="habi" onClick="HabiDsabi()"> Eu li e aceito os termos de uso 
    <a target="_blank" href="tos.html">termos de uso</a>.
  </p>
 <input type="button" class="btn btn-terciary"  name="envia" id="envia" value="Assinar" onclick="assinar()" disabled></form>
<!-- fim do botão -->
</div>

See more about window.Location in https://www.w3schools.com/js/js_window_location.asp

-1

Just as an alternative, the current answers already do what you want. This does not use javascript, only html and css optionally.

<button><a target="_blank" href='https://answall.com'>Click me!</a> </button>

You can put a little css to leave the <a> as a normal text also if you want.

a {
   color: black;
   text-decoration: none;
}
<button><a target="_blank" href='https://answall.com'>Click me!</a> </button>

Remembering that is not the best way to do, only an alternative method.

Browser other questions tagged

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