How can I make a button that sends me to another page that I specify? So far I've only been able to do it with the tag <a>
and its href and target attributes. But I can't do it with a <button>
.
How can I make a button that sends me to another page that I specify? So far I've only been able to do it with the tag <a>
and its href and target attributes. But I can't do it with a <button>
.
You can do it like this:
You don't occupy anything in the a tag, but thanks to location.href it tells you the address you want to reach
Try adding
target="_blank"
to a tag<a>
What I do is the following:
I don't know if it will be the best way, but it works for me.
Here I leave you another way to do the redirection;
We use a small JavaScript function to do the URL redirection.
As you have seen there are different ways to do it, this example that I have shown you can help you to be more efficient, for example, if you have to change the redirection eventually and you have different buttons on your website. To avoid searching the HTML code, create a small JavaScript file that contains the redirections, when you have to change them, you already have everything in the same document.
I don't know if the answer is a bit late. But I consider from your question that you are an apprentice, therefore the ideal would be a code like this: