/    Sign up×
Community /Pin to ProfileBookmark

Traping the back button

Is there a way in IE to trap when the back button is pressed to do things like prompt the user to save or do some function other than going back?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorNov 02.2005 — Nope. The browser interface default actions can not be changed from within a web page.
Copy linkTweet thisAlerts:
@GirevikauthorNov 02.2005 — Hmmm - my user is telling me that they know of a site that does that. Maybe I'll have to ask him to demonstrate.
Copy linkTweet thisAlerts:
@KorNov 02.2005 — there is possibility to ask user if he really wants to leave the page, but that means more than the back button. It referes at all the possible ways to leave a page. Furthermore, it will not stop the user to go back if he wants to by all means.

Here's the code:
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
window.onbeforeunload = function (evt) {
var message = 'Are you sure you want to leave?';
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}
</script>
</head>
<body>
</div>
</body>
</html>
[/code]
×

Success!

Help @Girevik 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 5.4,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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