/    Sign up×
Community /Pin to ProfileBookmark

Page expiration

hi does anyone know how to use javascript to make a webpage to redirect to a page expiration page once the back button is clicked?

For example i have this page call A and Page call B

Page A is clicked and redirect to page B. When the Back button is click to retrieve page A, it will reject and redirect to another page showing page expiration.

Can this be done?
I have tried all method such as META with no cache but it couldnt work.

Thank You

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@Willy_DuittOct 20.2004 — Try using [i]location.replace[/i] when redirecting from page A to page B... This will remove page A from the browser history so there should be no need to redirect again to [i]page expired[/i]....

.....Willy
Copy linkTweet thisAlerts:
@WebskaterOct 20.2004 — You can use the onbeforeunload event to trap the back button being clicked. You can set a variable on the page to false and, for example, set it to true before the page is being left in the normal way i.e. by clicking a link or submitting a form. In a function you run when the onbeforeunload event occurs you test for the value of the variable - if it is false you redirect to your expiration page. This may be IE only.
Copy linkTweet thisAlerts:
@Willy_DuittOct 20.2004 — onbeforeunload is IE only and if the [b]X[/b] is used to close the window the event will not even have a chance to fire before the window is closed...
Copy linkTweet thisAlerts:
@WebskaterOct 20.2004 — You might want to consider that using location.replace is counter intuitive to the way most people work. If you use location.replace and someone clicks the back button - the browser will go back to the last page in its history. This is not what people expect. Universally when people click the back button they expect to go back to the page they were just viewing. Using the onbeforeunload event will allow you to deal with 95% of visitors and using location.replace will allow the other 5% to enjoy the sensation of not seeing the page they were just looking at. If someone clicks the X to close the window - presumably you are not bothered.
Copy linkTweet thisAlerts:
@Willy_DuittOct 20.2004 — 95% of users do not use IE...

Besides, you are missing the point...

onbeforeunload support is wishy washy at best...

It may work ([i]at times[/i]) when browsing from one page to another but it will never have a chance to fire if the window is closed...

The closing of the window will not wait for the onbeforeunload event to fire... It has precedent and will close taking the unused event with it...

.....Willy
Copy linkTweet thisAlerts:
@Willy_DuittOct 20.2004 — To answer your other concerns regarding what a user may expect...

The OP is obviously trying to keep a visitor from returning to the page ([i]thus the reason for trying to redirect to another[/i])... If the page is no longer in the history, location.replace solves this problem and there is no difference in keeping a visitor from returning to a page by redirecting onload or removing from the history... In fact, I would find the latter less intrusive than being redirected...

Either way, the OP is trying to prevent someone from returning to the page and sanctimonious bs regarding what a visitor is used to or expecting is not the answer to his problem...

.....Willy
Copy linkTweet thisAlerts:
@WebskaterOct 20.2004 — I wasn't being sanctimonious - I was simply pointing out what people (in my experience) expect. If you click the back button, a typical user would expect to go back to the page they were just looking at. If you use location.replace to load page B, when they click the back button (which is what the question was about) they won't go back to Page A so the user will not be able to redirect them to his expiration page - which is what he said he wanted to do.

Closing the window is a red herring - who mentioned closing the window?

Using onbeforeunload properly will give the user exactly what he wants for a very, very high percentage of users. I know lots of people hate to admit it but, if you look at sites that publish figures showing which browser was being used to look by people viewing their sites - most of them show a very, very high percentage of IE users.

The user indicated he did not simply want to prevent people going back to page A, he wanted to trap that event and move them to an expiration page. Using location.replace would simply confuse many people because neither Page A nor the expiration page would appear.

So, I am sorry if you disagree with my solution and feel you have to point out that yours is superior. I disagree with you and, no doubt, the enquirer will select whichever method he feels will produce the most intuitive experience for his users.
Copy linkTweet thisAlerts:
@Willy_DuittOct 20.2004 — Of course you are being sanctimonious... This is the third thread I have been on with you which you have acted so... And yes the O/P will pick whatever method is best for him but I'll say it once last time...

onbeforeunload does not work as well as you think it does nor does writing code that will not work for [b]all[/b] users make any sense... What the heh are you going to do for those users whom you just broke the page because you used a propertiery method...

Besides, you have now waffled from 95% to what? A high percentage of users... Puleeeze... :rolleyes:

.....Willy
Copy linkTweet thisAlerts:
@WebskaterOct 20.2004 — Sorry, I take my post back. Your solution does exactly what the enquirer asked and no further input from anyone else was required. Please accept my apologies. Please refrain from further reply. I will not read it and this sort of dialogue is a waste of this forum's resources. If this forum allowed me to delete my previous post I would. Mea culpa, mea culpa, mea maxima culpa.
×

Success!

Help @Bruce_Lim 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.16,
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,
)...