Scroll To Top

Enter a query to search our site. Note that you can use "*" and "?" as wildcards. Enclosing more than one word in double quotes ("CSS Layout") will search for the exact phrase.

PVII Knowledge Base

1. Select a product ...
2. Select category ...
3. Search the Knowledge Base...

Question #202

With Tab Panel Magic 1(TPM) is it possible to have the page open with a randomly selected tab, that is, each time the page loads it would select a different tab as the initial tab.

The Answer

Prepared Nov. 2006 by Gerry Jacobsen, PVII

Note: The Tab Panel Magic 1 system has been retired.
The newer Tab Panel Magic 2 system includes this as built in feature, you simply check the Random box in the TPM2 user interface. Upgrade pricing from TPM1 is available.

Yes, the initial selected tab in TabPanel Magic 1 (TPM) can be randomly selected by adding this tweak:

1. Open the p7tpscripts.js file.

2. Copy and Paste this bit of code to the end of the file, being sure to create a new line for the paste insertion point.

function P7_randTP(){ //v1.0.0 by PVII-www.projectseven.com
  // random tab panel selector and trigger
  var i,tD,j=0,rD=new Array();
  tD=document.getElementsByTagName("DIV");
  for(i=0;i<tD.length;i++){
   if(tD[i].id&&tD[i].id.indexOf("p7tpb")==0){
    rD[j]=tD[i].id;j++;}}
  if(j>0){i=Math.floor(Math.random()*j);
   P7_TPtrig(rD[i]);}
 }

3. Save the file.

4. Next, we'll need to initialize this TPM randomizer function by adding this:

;P7_randTP()

to the page's <body> onload event. Typically, it would now look like this (the actual numbers may be different on your page depending your TabPanel options):

<body onLoad="P7_initTP(3,4);P7_randTP()">

That's it! The page will now open with a randomly selected tab.

Back to the questions list