Results 1 to 2 of 2

Thread: Question with location.href and window.history

  1. #1
    Join Date
    May 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Question with location.href and window.history

    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>

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by mik1962
    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:

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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •