I need to be able to identify what tab I am in within the browser. Isn\'t there some bit of information I can get from the browser to identify the tab? I don\'t need to kn
Since I don't have find no simple Javascript function as windows.currentTabIndex
, I have written some lines of Javascript to fix an ID on each browser tabs when they are loaded.
function defineTabID()
{
var iPageTabID = sessionStorage.getItem("tabID");
// if it is the first time that this page is loaded
if (iPageTabID == null)
{
var iLocalTabID = localStorage.getItem("tabID");
// if tabID is not yet defined in localStorage it is initialized to 1
// else tabId counter is increment by 1
var iPageTabID = (iLocalTabID == null) ? 1 : Number(iLocalTabID) + 1;
// new computed value are saved in localStorage and in sessionStorage
localStorage.setItem("tabID",iPageTabID);
sessionStorage.setItem("tabID",iPageTabID);
}
}
This code save last tab's index in localStorage
to update current value for new tabs and in sessionStorage
to fix page's id !
I must call defineTabId()
function in each pages of my application. Since I develop using a JSF templates, this is only defined in only one place :-)