Trying to get my button to act like a link (tried the <A>
tag and it would work if you open in a new tab but not if you click on it. Then tried this code and nothing. Suggestions?
<button onClick="location.href='/secure/edit.aspx?id=671'">Edit</button>
html button click redirectBy using HTML Anchor Tags <a>.. </a>, you can Redirect on a Single Button Click [html button click redirect]. To use HTML Anchor tags to redirect your User to Another page, you need to write your HTML Button between these HTML Anchor Tag's starting <a> and Closing </a> Tags.
To make HTML submit button redirect to another page, we have to use HTML's Form tags or HTML Anchor Tags. HTML Form tags allow us to Show Form data and also allow us to submit that Form data to another page using HTML Form tag's Action Attribute. HTML Anchor can link any HTML Element to Another Page.
With a few lines of JavaScript code, you can redirect visitors to another URL. The recommended function is window. location. replace() .
Using button tag inside <a> tag: This method create a button inside anchor tag. The anchor tag redirect the web page into the given location. Adding styles as button to a link: This method create a simple anchor tag link and then apply some CSS property to makes it like a button.
You need to explicitly say window.location
because this
in the context of the button is the button object itself. Ordinarily, JavaScript is run in the context of the window
object, so you don't need to do that.
<button onClick="javascript:window.location.href='/secure/edit.aspx?id=671'">Edit</button>
(Additionally, I also like to explicitly state that the script is javascript:
, but that's purely a personal thing.)
<button onclick="window.location='/secure/edit.aspx?id=671'">Edit</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With