Solved

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

Posted on 2003-11-05
5
772 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:Codescripter
ID: 9690797
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
ID: 9690826
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
ID: 9691534
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
ID: 9691552
**  document.referrer.value **  
0
 
LVL 15

Author Comment

by:Timbo87
ID: 9742978
Thanks.
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

734 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