Welcome to WebmasterWorld Guest from 54.162.19.123

Forum Moderators: open

Message Too Old, No Replies

Spry tab panel - select panel via URL parameter?

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

Junior Member

10+ Year Member

joined:Oct 19, 2004
posts:88
votes: 0


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?

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

Preferred Member

10+ Year Member

joined:July 5, 2005
posts:352
votes: 0


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>

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

Junior Member

10+ Year Member

joined:Oct 19, 2004
posts:88
votes: 0


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 });
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members