Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2003-11-05
5
Medium Priority
?
774 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 200 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

688 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