button click redirect to another page code example

Example 1: html button redirect

For button redirection you can use below code:

Using these two type <button> and <input> tag:

<a href="http://www.google.com/">
   <button>Visit Google</button>
</a>
  
or:

<a href="http://www.google.com/">
   <input type="button" value="Visit Google" />
</a>
  
<!--
I hope it will help you.
Namaste
-->

Example 2: js onclick redirect

<button onclick="location.href='www.yoursite.com'">Click Me</button>

Example 3: how to open a new html page on button click in javascript

<button id="myButton" class="float-left submit-button" >Home</button>

<script type="text/javascript">
    document.getElementById("myButton").onclick = function () {
        location.href = "www.yoursite.com";
    };
</script>

Example 4: how click button and redirect angular

import { Component } from '@angular/core';
import { Router } from '@angular/router';
// component details here...
export class MyComponent  {
  constructor(private router: Router){ }

  goToVotes($myParam: string = ''): void {
    const navigationDetails: string[] = ['/votes'];
    if($myParam.length) {
      navigationDetails.push($myParam);
    }
    this.router.navigate(navigationDetails);
  }
}

Tags:

Html Example