phillystyle123
asked on
sessions with jquery tabs
I'm using jquery tabs on this page:
http://dev.roydent.com/products.asp
User id= roydentdev
Password= roydent5100
this latest code that merwetta1 has so kindly developed for me - has been altered so a site visitor can click on a product listed on a tab, go to that product page then browse back to the jquery tabs and the tab that contains listing of the product they navigated to will load (instead of the default 1st tab).
this was working perfectly. but, there seems to be some sort of bug in the code - meaning that sometimes the tabs don't load at all (see screen shot) and sometimes they do. I've attached the js code as well.
http://dev.roydent.com/products.asp
User id= roydentdev
Password= roydent5100
this latest code that merwetta1 has so kindly developed for me - has been altered so a site visitor can click on a product listed on a tab, go to that product page then browse back to the jquery tabs and the tab that contains listing of the product they navigated to will load (instead of the default 1st tab).
this was working perfectly. but, there seems to be some sort of bug in the code - meaning that sometimes the tabs don't load at all (see screen shot) and sometimes they do. I've attached the js code as well.
<script type="text/javascript">
$(document).ready(function(){
var Url = document.location.href.split('#');
var Anchor = Url[1];
var SelectedCookie = getCookie('SelectedCookie');
var SelectedTabs = SelectedCookie.split(':');
var SelectedHTab = SelectedTabs[0];
var SelectedVTab = SelectedTabs[1];
if (!SelectedCookie)
{
if (Anchor == 'tabsv-1') SelectedHTab = 1;
else if (Anchor == 'tabsv-2') SelectedHTab = 1;
else if (Anchor == 'tabsv-3') SelectedHTab = 2;
else if (Anchor == 'tabsv-4') SelectedHTab = 2;
}
var htabs = $("#tabs").tabs();
$("#tabs2").tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
$("#tabs2 li").removeClass('ui-corner-top').addClass('ui-corner-left');
$("#tabs3").tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
$("#tabs3 li").removeClass('ui-corner-top').addClass('ui-corner-left');
// tabs4 is not implemented yet
// $("#tabs4").tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
// $("#tabs4 li").removeClass('ui-corner-top').addClass('ui-corner-left');
if (SelectedHTab)
{
// alert("SelectedHTab="+SelectedHTab+", SelectedVTab="+SelectedVTab); // uncomment this to see tab states retrieved from cookie
htabs.tabs('select', '#tabs-'+SelectedHTab);
if (SelectedVTab)
{
if (SelectedHTab == 1) $("#tabs2").tabs('select', '#tabsv-'+SelectedVTab);
else if (SelectedHTab == 2)
{
SelectedVTab = Number(SelectedVTab) + 2; // tabs3 uses "3" and "4" for names
$("#tabs3").tabs('select', '#tabsv-'+SelectedVTab);
}
}
}
saveTab = function saveTab()
{
SelectedVTab = 0;
SelectedHTab = htabs.tabs('option', 'selected') + 1; // have to add 1 because tab numbering starts at 0
if (SelectedHTab == 1) SelectedVTab = $("#tabs2").tabs('option', 'selected') + 1;
else if (SelectedHTab == 2) SelectedVTab = $("#tabs3").tabs('option', 'selected') + 1;
setCookie('SelectedCookie',SelectedHTab + ":" + SelectedVTab,1); // the last argument is the number of days to keep the cookie
// alert('setting cookie to '+SelectedHTab + ":" + SelectedVTab); // uncomment this to get an alert showing cookie being set
}
$(window).unload( function () { saveTab(); } );
});
function getCookie(NameOfCookie)
{
if (document.cookie.length > 0)
{
begin = document.cookie.indexOf(NameOfCookie+"=");
if (begin != -1)
{
begin += NameOfCookie.length+1;
end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin, end));
}
}
return null;
}
function setCookie(NameOfCookie, value, expiredays)
{
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
document.cookie = NameOfCookie + "=" + escape(value) +
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER