/    Sign up×
Community /Pin to ProfileBookmark

redirect to last page visited?

I want to make it so when you press any key it will redirect to you the page you last visited, but history.back() doesnt’ work. Anybody know how to do this?

<body onkeyup=”window.location = ‘history.back()'”>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@TJ111Dec 03.2007 — Remove the quotes around the "history.back()", as you are referencing an object, but with quote around it javascript will treat it like a string. The proper way to do this (i think) for full cross-browser support is like this:
<i>
</i>&lt;body onkeyup="window.location.href = window.history.back(1)"&gt;
Copy linkTweet thisAlerts:
@dtm32236Dec 03.2007 — I would first make it a function in the head:

<head>

<script type="text/javascript">

funtion redirect(){

history.go(-1);

}

</script>

</head>

<body onkeyup="redirect();">

i think that's correct - but I'm terrible with JS, so hopefully that'll work (maybe not though).
×

Success!

Help @Pixel-Artist 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.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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