Window history.back[]
Example
Create a back button on a page:
Go Back
The output of the code above will be:
Click on Go Back to see how it works.
[Will only work if a previous page exists in your history list]
Try it Yourself »
Definition and Usage
The
history.back[]
method loads the previous URL [page] in the history list.
The history.back[]
method only works if a previous page exists.
Syntax
Parameters
Return Value
Browser Support
history.back[]
is supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Is there a function I can attach as a click event of a button to make the browser go back to previous page?
Go Back
Second Method
Go back
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.......
answered Jun 3, 2013 at 10:52
Back
CroMagnon
1,1987 gold badges20 silver badges32 bronze badges
answered Oct 14, 2019 at 13:04
You just need to call the following:
history.go[-1];
answered Nov 9, 2011 at 15:44
Rich O'KellyRich O'Kelly
40.6k9 gold badges83 silver badges113 bronze badges
This is the only thing that works on all current browsers:
function goBack[] {
history.go[-1];
}
Go Back
answered Jan 26, 2017 at 13:57
Wim MostreyWim Mostrey
2675 silver badges8 bronze badges
Access window.history
and
then call back[]
window.history.back[]
answered Aug 24, 2021 at 12:31
1
the only one that worked for me:
function goBackAndRefresh[] {
window.history.go[-1];
setTimeout[[] => {
location.reload[];
}, 0];
}
answered Feb 17, 2021 at 18:15
DevTheJoDevTheJo
2,0192 gold badges20 silver badges22 bronze badges
You could use one of the following :
history.back[]
or window.history.back[]
You also go back to N number of pages with this one
history.go[-1]
answered Sep 3 at 23:48
2
100% work
Go Back
answered Jul 30, 2020 at 2:37
Fezal halaiFezal halai
7027 silver badges12 bronze badges