Obtaining URL of previous page

Discussion in 'ASP General' started by middletree, May 21, 2004.

  1. middletree

    middletree Guest

    I need to capture the previous page's URL. I thought I could find a way to
    do it with client-side code, but I have been unable to find a way to do
    that, so perhaps there's an ASP solution.

    Please note that this is for an Intranet app, so users will be coming to a
    particular page from another page. Specifically, I need the URL including
    the GET data that comes after the ".asp" part.

    Any code which can help is welcome. IE-specific is fine in this case.

    Here's what I am trying to accomplish:

    DisplayTickets.asp has a list of info which has a little bit of info about
    however many tickets met the search criteria. If the user wanted all tickets
    assigned to Bob which are from Customer A and were opened between March 1
    and April first, the results will show, one ticket per line, on
    DisplayTickets.asp. However, that page will have much more to its URL than
    just DisplayTickets.asp. It will have all the stuff I just described that
    was used to narrow down the search.

    In each row, the Ticket number is a hyperlink to the page called
    DisplayFullTickets.asp, which uses the GET method, so it will look like
    this:
    DisplayFullTickets.asp?TicketID=1000

    Because of some other specifications in the app, I have to use the GET
    method here. Otherwise, I could solve my problem very easily with hidden
    fields.

    Now here's deal: the boss wants me to make it so that when he clicks a
    ticket number in the list on DisplayTickets.asp, when he clicks BACK to that
    page later, from DisplayFullTickets.asp, he wants the most recent ticket
    number to be red, or in some other way acknowledge and display which was the
    last ticket he looked at, so he can go on to the next one.
     
    middletree, May 21, 2004
    #1
    1. Advertisements

  2. middletree

    Steven Burn Guest

    ThePage = Request.ServerVariables("HTTP_REFERER")
    Response.Write ThePage

    --

    Regards

    Steven Burn
    Ur I.T. Mate Group
    www.it-mate.co.uk

    Keeping it FREE!
     
    Steven Burn, May 21, 2004
    #2
    1. Advertisements

  3. Aaron Bertrand - MVP, May 21, 2004
    #3
  4. middletree

    middletree Guest

    Aaron:

    Thanks for this. I guess I didn't plug in the correct words to pull up this
    article when I went there before posting my question. I have a follow-up
    question for you:

    The 2nd item in your list of things that won't work is "A click on 'Home' or
    a Link with a defined URL"

    What do you mean by defined URL?
     
    middletree, May 21, 2004
    #4
  5. There is a "Links" toolbar available in Internet Explorer. If you use this,
    and put a shortcut there, and click on it, the referer will be blank.

    At least in the version of IE that was current at the time of writing the
    article.

    --
    Aaron Bertrand
    SQL Server MVP
    http://www.aspfaq.com/
     
    Aaron Bertrand - MVP, May 21, 2004
    #5
  6. Are you sure that was the original intent of the comment? Certainly this
    would be a link without a defined URL:

    <A HREF="" ONCLICK="foo()">Bar</A>

    function foo() {
    window.location.href = "Something.asp"
    }

    In such a case, there is no HTTP_REFERER.


    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
     
    Dave Anderson, May 24, 2004
    #6
  7. Are you sure that was the original intent of the comment?

    Yes.
    Right, and that's covered by "A JavaScript location.href or
    location.replace()" ... whether or not there is a valid URL in the HREF
    attribute, there is no HTTP_REFERER.

    A
     
    Aaron Bertrand - MVP, May 24, 2004
    #7
  8. I updated the article so it is less ambiguous.
     
    Aaron Bertrand - MVP, May 24, 2004
    #8
  9. That example, of course, needs a "return false" in the ONCLICK handler:

    <A HREF="" ONCLICK="foo();return false">Bar</A>



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
     
    Dave Anderson, May 24, 2004
    #9
  10. middletree

    Evertjan. Guest

    Dave Anderson wrote on 24 mei 2004 in
    microsoft.public.inetserver.asp.general:
    Advisable, but not neccessary, as the page should probably be
    location.hreffed [replaced] before the a href gets its chance to execute.
     
    Evertjan., May 24, 2004
    #10
  11. middletree

    Joseph Guest

    Joseph, Jun 20, 2004
    #11
  12. middletree

    Joseph Guest

    Joseph, Jun 20, 2004
    #12
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.