/    Sign up×
Community /Pin to ProfileBookmark

The redirect and the cookie

I’m racking my brain on this one and it’s such a common problem I have to think someone has an answer.

I am using a JavaScript redirect to direct users to a page. The problem is when they press the back button they do that stupid loop thing.

What I would like to do is set a cookie on the page that’s redirecting the user. This cookie will let the browser know if the users been there before. If they have then the user will be redirected back on page in their history. Meaning, the back button would work properly.

There has to be code that does this already existing. All the code I’ve tried to write has failed.

Thanks

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@TageMar 31.2004 — You could make a button that stands out on your second page that sends them back twice into the history. So they can click that instead of using their browser's back button.
[code=php]<a href="javascript:history.go(-2)">CLICK THIS TO GO BACK, YAH YOU! I'M TALKING TO YOU!! DON'T EVEN THINK ABOUT PRESSING YOUR DEFAULT BROWSER BACK BUTTON!!!</a>[/code]
Without that space between java and script. (why oh why does it do that?)

But don't say that, lol. Cookies are difficult to manage. You'd have to ask someone else about that. You could also name your window when redirecting the user to the second page like so...

[U]Redirecting Page[/U]
[code=php]<html>
<head>
<script type="text/javascript">
<!--
if(window.name!="noRedirect"){
window.name="noRedirect";
location.href="page2.html"/*or whatever tag you use to redirect, I wouldn't know*/}
else{
window.name="redirect";
history.back();}
//-->
</script>
</head>
<body>
</body>
</html>[/code]


That *should* work. Hope it helps, later.
×

Success!

Help @mc4 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.15,
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,
)...