Onclick javascript to make browser go back to previous page?

Doc Holiday picture Doc Holiday · Nov 9, 2011 · Viewed 501.9k times · Source

Is there a function I can attach as a click event of a button to make the browser go back to previous page?

<input name="action" type="submit" value="Cancel"/>

Answer

rogerlsmith picture rogerlsmith · Nov 9, 2011

Add this in your input element

<input
    action="action"
    onclick="window.history.go(-1); return false;"
    type="submit"
    value="Cancel"
/>