Onclick javascript to make browser go back to previous page?

go back to previous page javascript
javascript how to go back to previous page without refresh
javascript go back 2 pages
html back button without javascript
jquery go back to previous page
php go back to previous page after submit
php back to previous page without refresh
return to previous page

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"/>

Add this in your input element:

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

History back() Method, The onclick event can be specified with the method to go back one page in history. Syntax: window.history.go(-1). Note: If we want to go  There is two popular way to make browsers go back to the previous page by clicking JavaScript event, both methods are described below: Method 1: Using history.go() method: The go() method of the window.history object is used to load a page from the session history. It can be used to move forward or backward using the value of the delta parameter.

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"/>

Onclick javascript to make browser go back to previous page , <button onclick="goBack()">Go Back</button>; <script>; function goBack() URL in the history list. This is the same as clicking the “Back button” in your browser, or history.go(-1). This method will not work if the previous page does not exist in the history list. In javascript, to get the path, you can use: Ex: … The browser should reuse cached page (assuming browser settings and page http header settings permit doing so). – ToolmakerSteve Apr 30 at 14:42 add a comment |

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.......

How to make browser to go back to previous page using JavaScript , back() method to tell the browser to go back to the user's previous page. One way to use this JavaScript is to add it to the onclick event attribute of  the above simple code make the previous and next page location onClick. history.go(-1); is make go back one time back. similarly we can make change any number, as we need, where to go and how page back. that's what the number mentioned. history.go(+1); is make go to next page in browser.

<input name="action" type="submit" value="Cancel" onclick="window.history.back();"/> 

Javascript go back to previous page, Here is the button to take you back to previous page. Note that the onClick event can be set to history.go(-3); to move back three steps. We can use +2 also to move  This page will have a button or a link and by clicking it browser will return to previous page. This can be done by using html or by using JavaScript in the client side. Code for HTML back button can be placed any where inside the page ( or inside body tag ). This button will work in same as the back button at the tool bar of our browser. Here also we can set to go previous one or more than one step of pages.

You just need to call the following:

history.go(-1);

How to create an HTML back button, It contains the browser session history, a list of all the pages visited in the current </script> <button type="button" onclick="getViews();">Get Views Count</button​> object i.e. history.back() to go back to the previous page in session history. A back link is a link that moves the browser backwards one page, as if the user had clicked the Back button available in most browsers. Back links use JavaScript. It moves the browser back one page if your browser supports JavaScript (which it does) and if it supports the window.history object, which is necessary for back links.

HTML and JavaScript code for back button in to go previous pages, Browsers already have "back" buttons, so you'd better have a darn good reason for needing to put one on your page! Input button with inline onclick="history.​back(-1)" />. This is totally obtrusive, but you could fix that by only appending this button through JavaScript. Frontend Masters is the best place to get it. They have  One major issue with JavaScript-based applications is that they break the Back button. If you update content on the page with JavaScript rather than loading a new page from the server, no entry made is in the browser history; so when the user clicks Back, expecting to go back to the previous state, they end up at the previous site instead.

JavaScript Window History, HTML: <img SRC="back.gif" BORDER=0 height=64 width=112> above: <a href​="#" onclick="history.back();return false">Go Back To The Previous Page</a>  The back() method loads the previous URL in the history list. This is the same as clicking the "Back button" in your browser, or history.go(-1). Note: This method will not work if the previous page does not exist in the history list. Tip: To load the next URL in the history list, use the history.forward() method.

"Go Back" Button, In this video you will find information about how to make browser go back to previous page with JavaScript //EASYWEB - YouTube channel about web-development and high technologies.

Comments
  • window.history.back()
  • This doesn't work in all browsers for me, I had to do the following <input action="action" type="button" value="Back" onclick="window.history.go(-1); return false;" /> This answer is quite old, so it could have been an issue introduced into more modern versions of browsers. :)
  • Does this show the previous page from cache or reloads the previous page from the server?
  • What's the action="action" part for? And is it valid html??
  • @Adrien - its javascript, so it is running in the browser. The browser should reuse cached page (assuming browser settings and page http header settings permit doing so).
  • Put this to the button onClick handle
  • You could be more clear like giving the answer in the code
  • What's the browser support on that?
  • @JeromeJ it is a link that does nothing if JavaScript isn't enabled/working (for whatever reason) on the page. If JavaScript is working, it takes the browser back one page.
  • Works fine, but oftentimes if user decides to change language on specific page with the button like this, the back button to previous page will turn the language back, instead of page...