Create a back button on a page:
The output of the code above will be:
<!DOCTYPE html> <html> <body> <button onclick="goBack()">Go Back</button> <script> function goBack() {/*from ww w . j a v a 2s.c om*/ window.history.back(); } </script> </body> </html>
The back()
method loads the previous URL in the history list.
This is the same as clicking the "Back button" in your browser.
This method will not work if the previous page does not exist in the history list.
history.back();