/    Sign up×
Community /Pin to ProfileBookmark

Setting Back Button History

I need to set the the page the browser will go to when the back button is pressed. Any ideas on how to do this with javascript without using the location.replace method? Also, is there any way to determine when the back button has been pressed and run a function because of it? Thanks!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Zach_ElfersDec 05.2002 — I'm not sure exactly what you mean, but this will give you a back button <a href="javascript:history.back(-1);">Back</a>.
Copy linkTweet thisAlerts:
@KruezauthorDec 05.2002 — What I have is a web application that I need to return to the main page whenever the back button is pressed in the browser. I also can't disable the back button and provide my own.
Copy linkTweet thisAlerts:
@spufiDec 05.2002 — Stupid question time. Why on earth would you want to do this? If you want people to be one click away from the main page, then have a link to the main page on all of your pages. If you overwrite the back button you take away a major feature of a browser. What if someone is five pages deep into your site and they need to go back one page? You want to send them back to the main page so they can click through four pages just to get where they wanted to be?
×

Success!

Help @Kruez spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...