Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Remove anchor hash from URL
03-05-2010, 09:51 AM #1
- 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=123along 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.
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?
03-05-2010, 06:16 PM #2
- 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:
echo "<a href=\"mbthreads.php?".str_replace("&m=dec", "", $_SERVER['QUERY_STRING'])."\">\n";