Welcome to WebmasterWorld Guest from 54.234.129.215

Forum Moderators: open

Message Too Old, No Replies

Spry tab panel - select panel via URL parameter?

     

rich_b

1:10 pm on Aug 3, 2007 (gmt 0)

10+ Year Member



I have a page that contains a set of tabbed panels using Spry JS code. I can use the following code to set the default panel when the page loads which works fine:

<script type="text/javascript">
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1", { defaultTab: 1 });
</script>

What I'd like to do now is change the code so defaultTab gets its value from a query string parameter when the page is called.

i.e. [mydomain...]

I've tried a few things but can't get it to work. Is it possible?

Trace

1:44 pm on Aug 3, 2007 (gmt 0)

10+ Year Member



Without actually being able to test it, I think something like this could work;
<script type="text/javascript">
function getURLParam(strParamName){
var strReturn = "";
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 ){
var strQueryString = strHref.substr(strHref.indexOf("?"));
var aQueryString = strQueryString.split("&");
for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
var aParam = aQueryString[iParam].split("=");
strReturn = aParam[1];
break;
}
}
}
return strReturn;
}

var theTab = getURLParam('tab');
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1", { defaultTab: theTab });
</script>

rich_b

2:15 pm on Aug 3, 2007 (gmt 0)

10+ Year Member



Hi Trace, thanks for replying. We're half-way there with your solution. The get URL bit works. I used alert(theTab) to check that the var had got the right value which it had. The problem is that the code that sets defaultTab to the value of theTab isn't working.

var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1", { defaultTab: theTab });
 

Featured Threads

Hot Threads This Week

Hot Threads This Month