Forum Moderators: open

Message Too Old, No Replies

Bookmarking - AJAX and NON AJAX Solution Required

Both types of users to use the exact same bookmark?

         

dcaunt

8:39 am on May 10, 2006 (gmt 0)

10+ Year Member



I'm a reasonably experienced web developer, but this has stumped me somewhat.

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.

jshanman

1:09 pm on May 10, 2006 (gmt 0)

10+ Year Member



You could use javascript in this way:
var loc = document.location;
if (loc.hash!= "") window.location = loc.href.replace("#","?");

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

moltar

1:20 pm on May 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think vBulletin has a similar solution. When you link to some thread with # in it, it redirects to? page.

dcaunt

1:24 pm on May 10, 2006 (gmt 0)

10+ Year Member



I'll try to clarify.

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

jshanman

3:02 pm on May 10, 2006 (gmt 0)

10+ Year Member



Without javascript, there is no "hash" as far as the browser can tell.

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

dcaunt

3:16 pm on May 10, 2006 (gmt 0)

10+ Year Member



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.

jshanman

4:18 pm on May 10, 2006 (gmt 0)

10+ Year Member



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

dcaunt

4:29 pm on May 10, 2006 (gmt 0)

10+ Year Member



The permalink is not a bad idea - it basically uses the google maps solution.

The other solution is to use two sites, and to redirect between the two if a user is not in the site that supports them. This is possible at both ends, but not my preferred solution.