Link to home
Start Free TrialLog in
Avatar of Timbo87
Timbo87

asked on

What's wrong with this code? (history.previous)

Here's the objective of the code: If this page was accessed by a link, the errorurl is set to the page that accessed it (history.previous) if this page was accessed without a previous link, errorurl is set to the current URL.

errorurl = history.previous
if(errorurl==undefined) errorurl = window.location

Thanks
Avatar of Codescripter
Codescripter

what about a different approach:

<html><head><title>test</title>

<script langauge="JavaScript">
function GoPrevious() {
  if (history.length != 0)
    window.history.back();
  else
    window.location.reload();
}
</script>
</head>

<body>
<form name="theform">
<input type="button" value="Previous" onclick="javascript:GoPrevious();">
</form>

</body></html>
Avatar of Timbo87

ASKER

Thanks for the answer, but I don't want the browser page to change. I need to it to receive information. It's for a server error handler (404, 500, etc) and if they clicked a link and got a 404, I want it to report the page that they came from (history.previous). If they typed it in (no history) and got the error, I want it to display the page URL they typed in (window.location).
ASKER CERTIFIED SOLUTION
Avatar of incongruent
incongruent

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
**  document.referrer.value **  
Avatar of Timbo87

ASKER

Thanks.