PDA

View Full Version : Question with location.href and window.history



mik1962
05-03-2005, 03:36 PM
I've been trying to make this work for a few days now, but I can't figure out how to do it. I created this form that has a text field that shows the url of the current page in the browser. What I actually want it do display is the url of the previous page in the web browser history, basically, the url of the page that would appear of I would hit the "back" button in my browser. I've played around the window.history command, but I can't get it to work. Do you know of a simple way of doing this?

The script I am using in the page is the following:



<input type="text" name="Page_Containing_Error" value="" size="60" />

<SCRIPT LANGUAGE="JavaScript">

<!--
{
document.form1.Page_Containing_Error.value = location.href;
}
// -->
</SCRIPT>

mwinter
05-03-2005, 07:10 PM
I created this form that has a text field that shows the url of the current page in the browser. What I actually want it do display is the url of the previous page in the web browser history [...]You cannot. It is considered an invasion of privacy to have access to a user's browsing history. You can navigate back through the list, but you cannot get access to the URLs themselves.

You may be able to use the referring URL, but:


In certain situations, the Referer [sic] may not reflect the previous history entry. I haven't checked, but a server-side redirection may send its own referring URL, however user agents don't add locations which result in redirection to the history.
The Referer [sic] is considered optional and user agents do allow it to be disabled if the user is concerned about privacy. Some proxies may effectively do the same thing. Similarly, the Referer can be falsified.
Another approach is to encode the previous URL and send it along in the URL to your page. However, that may not be at all practical.


<input ... />The fact that the starting and closing tags of the script element is in capitals, clearly shows you aren't writing XHTML. In that case, don't end the start tags of empty elements with a slash. That has a very particular, though (admittedly) rarely respected, meaning in HTML.


<SCRIPT LANGUAGE="JavaScript">
<!--Both the language attribute, and the practice of 'hiding' script and style data using SGML comment delimiters, is wholly out-dated and best avoided. Use the type attribute instead:


<script type="text/javascript">
/* ... */
</script>Mike