PDA

View Full Version : Help to Remember last tab used in the Tab Content Script (v 2.2)



DRandyD
12-11-2009, 02:14 AM
I am using the Tab Content Script (v 2.2). After closing all browser windows and then coming back to my site at a later time, I want the script to be able to remember the last tab I was on.

I am wondering if anyone could help me with this. Is this possible?

Thanks

jscheuer1
12-11-2009, 02:43 AM
OK, the ajaxtabs.js script only supports session only persistence. So it will need to be edited. Open it up with a text only editor like NotePad. At the beginning add the highlighted:


//** Ajax Tabs Content script v2.0- Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
//** Updated Oct 21st, 07 to version 2.0. Contains numerous improvements
//** Updated Feb 18th, 08 to version 2.1: Adds a public "tabinstance.cycleit(dir)" method to cycle forward or backward between tabs dynamically. Only .js file changed from v2.0.
//** Updated April 8th, 08 to version 2.2:
// -Adds support for expanding a tab using a URL parameter (ie: http://mysite.com/tabcontent.htm?tabinterfaceid=0)
// -Modified Ajax routine so testing the script out locally in IE7 now works

var ddajaxtabssettings={}
ddajaxtabssettings.bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
ddajaxtabssettings.loadstatustext="<img src='ajaxtabs/loading.gif' /> Requesting content..."
ddajaxtabssettings.persitdays=1 //Set number of days for persistence, use 0 for session only

Next find this function:


ddajaxtabs.setCookie=function(name, value){
document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/)
}

Change it to:


ddajaxtabs.setCookie=function(n, v, d){
d = d || ddajaxtabssettings.persitdays || null;
if(d){var dt = new Date();
dt.setDate(dt.getDate() + d);
d = '; expires=' + dt.toGMTString();}
document.cookie = n + '=' + escape(v) + (d || '') + '; path=/';
}

Save and use this modified version. If desired, you may change the ddajaxtabssettings.persitdays value at the beginning of the file. Whatever it is set to will be the number of days the cookie will persist for.

Also be sure to enable persistence in your on page ddajaxtabs declaration, ex:


var countries=new ddajaxtabs("countrytabs", "countrydivcontainer")
countries.setpersist(true)
countries.setselectedClassTarget("link") //"link" or "linkparent"
countries.init()

However, if the browser (yours or anyone else's) is set to not accept cookies or to destroy cookies on exit, this will not work. Generally though most folks accept cookies and allow them to persist from session to session if set that way by this script.

DRandyD
12-12-2009, 03:16 PM
Finally getting back

OK I'll try it.

Thanks for your help John.

jscheuer1
12-13-2009, 12:22 AM
I just double checked and there may be a problem in some browsers, you should change (in the new setCookie function):


ddajaxtabs.setCookie=function(n, v, d){
d = d || ddajaxtabssettings.persitdays || null;
if(d){var dt = new Date();
dt.setDate(dt.getDate() + d);
d = '; expires=' + dt.toGMTString();}
document.cookie = n + '=' + escape(v) + (d || '') + '; path=/';
}

to:


ddajaxtabs.setCookie=function(n, v, d){
d = d || ddajaxtabssettings.persitdays || null;
if(d){var dt = new Date();
dt.setDate(dt.getDate() + d);
d = '; expires=' + dt.toGMTString();}
document.cookie = n + '=' + v + (d || '') + '; path=/';
}

DRandyD
12-14-2009, 12:30 PM
Thanks for your reply and checking