views:

40

answers:

1

Need a simple approach to get a Unique ID in javascript for tab windows in Internet Explorer. I basically was wondering if there is something like document.tab.indexnumber, which there is not. So the real question is if there is anything that can be used to generated this or find out what tab you are in ? Similarly I should be able to get another unique id for another instance of internet explorer ?
I cannot use an IE addon for this.

An additional complication is that we could use a random number generator plus timestamp for a unique id as suggested below in one of the answers. But how can I keep this same number across the same session for that tab. If I store it in a session variable it is shared between all tabs/windows with that session.

We could put the id in the url or a hidden field, but that solution would be to intrusive to the design of the site. Looking for something less intrusive.

+1  A: 

Simply quoting an answer from a previously asked question:

There have been a couple attempts at this. The question is: do you want actual GUIDs, or just random numbers that look like GUIDs? It's easy enough to generate random numbers. From http://note19.com/2007/05/27/javascript-guid-generator/:

 function S4() 
 {    
     return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
 } 
 function guid() 
 {    
     return(S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
 }

However, note in the comments that such values are not genuine GUIDs. There's no way to generate real GUIDs in Javascript, because they depend on properties of the local computer that browsers do not expose. You'll need to use OS-specific services like ActiveX: http://p2p.wrox.com/topicindex/20339.htm

Eton B.
Thank you that is an interesting approach. Then the question is still how you can make sure this is guaranteed unique across different tabs and windows that have the same session id, preferably without communicating between parent/child relationship.
mrjohn
This will work and to ensure uniqueness across the same session I could include a timestamp. But how can I keep this same number across the same session for that tab. If I store it in a session variable it is shared between all tabs/windows with that session.
mrjohn
Accepting the solution, although still needs lot of work, this is on the right track. Best would be to pass the generated id from page to page, but then there is still problem when you leave the site in between page hits
mrjohn