Solved

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

Posted on 2003-11-05
5
767 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:Timbo87
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:Codescripter
Comment Utility
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>
0
 
LVL 15

Author Comment

by:Timbo87
Comment Utility
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).
0
 
LVL 2

Accepted Solution

by:
incongruent earned 50 total points
Comment Utility
you can find out the url that brought the browser to the page by accessing the refferer header in the request.  


<script>
document.write(document.referrer);
</script>
0
 
LVL 2

Expert Comment

by:incongruent
Comment Utility
**  document.referrer.value **  
0
 
LVL 15

Author Comment

by:Timbo87
Comment Utility
Thanks.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now