Onclick javascript to make browser go back to previous page?
Add this in your input element
<input
action="action"
onclick="window.history.go(-1); return false;"
type="submit"
value="Cancel"
/>
history.back()
or
history.go(-1)
Put this to the button onclick
handle. It should look like this:
<input name="action" onclick="history.back()" type="submit" value="Cancel"/>
For Going to previous page
First Method
<a href="javascript: history.go(-1)">Go Back</a>
Second Method
<a href="##" onClick="history.go(-1); return false;">Go back</a>
if we want to more than one step back then increase
For going 2 steps back history.go(-2)
For going 3 steps back history.go(-3)
For going 4 steps back history.go(-4)
and so on.......
<input name="action" type="submit" value="Cancel" onclick="window.history.back();"/>
Simple. One line.
<button onclick="javascript:window.history.back();">Go Back</button>
Like Wim's and Malik's answer, but just in one line.