How to Redirect after Click on Button

67 Views Asked by At

I'm using Landing page so I already have button I want to redirect people after clicking on this button the button id is: button-c86b272c I want to redirect people after clicking on this button not create new button .

I have this code to redirect after time out :

<meta http-equiv="refresh" content="10; URL=www.google.com/" />

but I want one to redirect after click on exicting button not new button I tried change the first code to this :

<meta http-equiv="refresh" onclick="button-c86b272c; URL=www.google.com/" />

but it did not work something isn't right Hope You help me

1

There are 1 best solutions below

0
xkcm On

The meta tag is not a visible DOM element, it means it does not have a "body", thus cannot be clicked on. meta tag is used to describe metadata about your page, or set HTTP headers.

To redirect to a specific URL after the button is clicked you can use JavaScript:

// First we need to create a handle to the DOM element
const buttonElement = document.getElementById("button-c86b272c");
// Then we add an event listener, which will execute a passed function after the event (in our case "click") is fired
buttonElement.addEventListener("click", () => {
  // We set the destination URL, the page reloads automatically
  window.locaton = "www.google.com/";
});

Add this code to your page or put it in a separate file and make sure to import it or you can add the event listener directly in your HTML using the onclick property, like this:

<button id="button-c86b272c" onclick="window.location = 'www.google.com/'"></button>

However this approach is not recommended and it's best to put your JavaScript in a separate file and not mix it into the HTML.

Hope this helps!