views:

427

answers:

3

Hi,

I'm working on a site where we need "dynamic" breadcrumb generation.

Pages within this application are not specific children of the other, so when the user is browsing one of them, I can't simply retrace steps back up.

I could have the following breadcrumbs-like lists: (updated)
* inbox > message > user profile
* search results > user profile
* search results > user profile > new message

( FYI; there will be a few dedicated parent pages that will reset the whole stack. Also there will be a check that prevents recursion. )

So... To accomplish this, I have to remember where the user has been, and in what order. I reckon the most elegant and reliable way to do is, is write a mechanism that remembers the user's history in the session.

If I do that though, the whole thing will break when a user opens a new browser window or tab.

To fix that, I could store this data in the querystring. Though different browsers/proxies have different limits of data that can be transferred that way. So, one day, this will probably break as well.

Does anyone have an idea on how to implement this?

Or;

Does anyone know how to reliably identify different browsers windows?

(I'd rather not rely on javascript for this, unless it's my only workable option. I use dojo toolkit for the frontend)

thanks in advance!

+2  A: 

On HTML5 compatible browsers I would save these on the local storage.

You can detect a new tab open like this:

  • on page load set a cookie by javascript
  • use the onbeforeunload event to clear the cookie

When the visitor will open your site, it will set a cookie eg session=1, if they click on a new link on your site, when they leave the site the cookie will be eg session=0 but as soon as they arrive again on your site it will be session=1. When the visitor will open a new tab, it will encounter a session=1 so probably will do that session=2. You got the point?

Pentium10
Yeah, nice one. Sounds like a good way to go.I'm gonna play with this, and share my findings..Thanks for the quick reply!!
Maurice
I've tested this in firefox, and it does seem to work. So now I am able to detect when the user opens a new tab or window. Would you happen to know how to tell them apart from eachother? IE; a user has two tabs open, and closes the first one. How would the second one (after a refresh or new url) know if it's #1 or #2?
Maurice
you can set cookies for this, an index value, you can have values like 10-20-30, so if when the 2nd tab opens and sees there is a cookie with 10, it creates cookie 20 ... that's different, and will be always cookie 20
Pentium10
Maybe I'm missing something, but when each page deletes it's cookie-index on unload, how does it know which cookie-index this specific tab had in the previous page? What prevents the tab indexes from getting mixed up?
Maurice
+1  A: 

window.name survives a new document load. So you can write a history string to window.name and then read it back from the next page, or use a generated name as a key for storing window-specific cookies/sessions.

I don't think this is a good idea though. “Breadcrumbs” are traditionally a hierarchical navigation device, not a history list. The browser already provides a perfectly good history list on the back/forward buttons that it is not useful to reproduce on the page; presenting an on-page history list, especially in a format that is normally a hierarchical place marker, is more likely to confuse users than to be of any help.

bobince
Cheers mate.I agree with what you say, though this isn't a normal webpage. What I'm trying to achieve is more like a merge between breadcrumbs and history. I've updated the page examples to better explain the scenario.
Maurice
in firefox; window.name gets reset when opening a new window, which is good. But opening a tab will not reset it. Haven't tested it on other browsers. It's a good tip, but not useful in this particular situation. Cheers for the help though!
Maurice
How do you mean, opening a new tab? If I middle-click on a link from a document that's set `window.name='foo'`, the new tab definitely doesn't inherit the name. I get a new blank name string same as on a complete new window.
bobince
Whoa, I just retested this in firefox, and you are right. Now it does reset the name when I open a new tab. I must've made an mistake while testing. My apologies. AFAYK, are there any (javascript-capable) browsers where this doesn't work?
Maurice
I'm not aware of any. It's not standardised, but it's one of those ‘DOM Level 0’ things that Netscape did and no-one's changed since. HTML5 mentions `window.name`, but doesn't go into any detail.
bobince
Thank you very much. This looks like the way to go! For others, there's more info on this at http://www.boutell.com/newfaq/creating/scriptpass.html
Maurice
hey maurice - just wanted to check with you and find out if you implemented the window.name approach in your project? if so, what were the results/any issues etc? i'm facing a similar task and I was going to implement using the same method.
ace
+1  A: 

I asked a similar question a few months ago. The top answer - which I will am planning to go with - suggested building a path, and parsing that using a combination of mod_rewrite and PHP:

www.mysite.com/inbox/message/user_profile/12345/new_message

Up to a certain point (the request URL should never grow larger than 1024 bytes), that can be quite a good solution. An additional advantage is that the breadcrumb path can even survive sessions, and works in links forwarded to others (if that is desirable in your scenario).

Another thing, looking at your examples, I can't really see the need to reset the history when the user opens a new page, or to take different browser windows into consideration at all. There is a logical hierarchy (not a history) and why should the system start changing then hierarchy just because I choose to open the new message editor in a new tab?

Pekka
Cheers mate. I already use a routing mechanism that makes use of modrw, to add some kind of history to it will be probably end up with other problems. Also this will generate duplicate content on different urls, which is not a good seo practice. Though my example urls aren't public, some will be.You're right, the history will not have to be reset, but rather cloned. Because in a new window, a different path can be chosen than in the original window. Hence I have to tell them apart somehow. (or rely on the querystring, but as you say, that can become problematic as well)
Maurice