views:

90

answers:

4

Specifically. I am making an ajax app and trying to preserve the back button. My javascript is working properly and registering a new url in the address bar with an anchor-like hash in the url:

http://t2b.localhost/#/clients/

I can catch the url when the page loads with javascript and load the "clients" page, but I want to know if there is a way to read the entire url with php or with htaccess? Looking at normal variables, I seem to only be able to get the url up to the occurrence of the "#" (http://t2b.localhost/).

A: 

I'm pretty sure that you can't parse it strictly with PHP because the hash part is parsed only on the client-side ( Javascript ).

For history I'd recommend Ben Alman's BBQ plugin.

See: http://stackoverflow.com/questions/940905/can-php-read-the-hash-portion-of-the-url

meder
+4  A: 

The browser don't send to the server the fragment (the text after the #) part of the url. It is intended to be used locally by the client.

In firefox (and in explorer too) there is document.location.hash that contains the fragment part of the URL. If you use javascript you can read it and send his value into a common variable.

Eineki
A: 

You could use javascript and set a cookie as the current URL then get it with PHP

Galen
+1  A: 

Please use any of the available javascript libraries to track the history state or browse by ajax requests. There are so many problems involved, such as certain browsers not notifying scripts when the hash part changes, or not adding a pseudo-'navigation' event to the browser's history list etc., that you'll end up recreating an expensive wheel that wouldn't work very well. I recommend YUI's History library, although it has problems on Google Chrome.

lifeforms
Thanks for the vote of confidence :)
Jage