Solved

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

Posted on 2003-11-05
5
771 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

696 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