Forum Moderators: open
The most common solution to bookmarking pages within AJAX applications is to use the # hash symbol and to read this using javascript. This also enables the back button.
e.g. index.php#page3
However, I'm looking for a solution where both AJAX and non ajax users should be able to exchange links with each other. PHP cannot detect the value of the hash (page3 for example) and this bookmark would be useless to a non ajax user.
Does anyone know of a good solution to this?
I'm thinking of possibly using GET variables - this would allow the non ajax user to pass a bookmark to the ajax user, but this is still not a solution for ajax users to pass the bookmarks the other way, as any subsequent navigation by the ajax user will generate # links, unless I can modify the query string without reloading the page (and I havent found a way to do so).
Any help or ideas are appreciated - Ive googled a great deal on this to no avail.
You would want this at the top of the page before anything else so it would re-direct right away. This would work as long as the GET structure is the same for both the hash and php.
- JS
Assume the 'non ajax user' has javascript disabled, and cannot convert # to? - ruining the bookmark. I appreciate there is a difference between ajax support and javascript support, but I'm looking for a solution for those with NO javascript or javascript disabled.
The problem comes when the ajax user gives his bookmark url to a non ajax user.
The non ajax user visits index.php#485 and sees the home page while the ajax user would intend that they see something like article 485 for example.
Using GET means that the AJAX is no longer a single page, and a new request is fired off if you change the document.location
The only exception is the old fasioned link & name.
<a id="page5" name="page5"></a>
<a href="#page5">go to page 5</a>
With this in mind, you could have a <noscript> section that prints ALL *pages* (or whatever). Each *page* would have an <a id="page(x)" name="page(x)"></a> at the beginning. Then when this page is opened on a non-script browser, it would jump the the section. If script was enabled, it can re-direct right away to the javascript/ajax version.
That's the only thing I can come up with...
- JS
Indeed, alas there are potentially thousands of pages and this is not practical. I have concluded this is not possible!But please try to prove me wrong.
I agree that it is not practical, but AFAIK it's the only *automatic* way considering:
1. PHP cannot read anything after #, or even know if the url contains a #
2. If javascript is disabled, there is no way to read the hash apart from directing the browser to a <a name="hash"></a> tag.
You could consider creating a "permalink" that updates with ajax, then just try to direct users to bookmark the permalink(containing? instead of #) rather then the page they are on. I think people are learning the concept of "permalink" enough for that to be effective.
- JS