Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Thanked 0 Times in 0 Posts

    Remove anchor hash from URL

    I have a search page containing a form. When submitted the results are displayed on the same page and displayed in rows.

    Each row has a title with a hyperlink. The hyperlink goes to the detail page, carrying across the id e.g. detail.php?id=123 along with the other search parameters in a session.
    The link also uses the id as the anchor name e.g. <a href="detail.php?id=123" name="hash123">The Row Title</a>

    I then use the id at detail.php to generate a 'back to results' link, with the #hash appended e.g. search.php?param1=abc&param2=def#hash123
    This then scrolls the page down so that the user is taken back to where they left off.

    The problem here is if the user goes back to the search page (from details.php) and changes the filters/keyword, runs the search again - the #123 stays in the URL. I need to remove this when the form is submitted again.

    Does anyone know how I can do this?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Thanked 637 Times in 625 Posts
    I had to do something similar not long ago. This is probably not the "best practices" way to do it, but I just manipulated the query string (accessed it via $_SERVER['QUERY_STRING']) before I reloaded the next page. I did something like:

    PHP Code:
    echo "<a href=\"mbthreads.php?".str_replace("&m=dec"""$_SERVER['QUERY_STRING'])."\">\n"


    Posting Permissions

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