Accordion Menu / Posts /

Opening submenu using a query string solution

0

I use accordion menu not for a menu but to display a multiple level faq page ( categories / questions / answer ). I have only one faq page and I wanted to be able to link to a specific question/answer pair from elsewhere. Using the excellent information on http://www.menucool.com/vertical/accordion-menu#open_close, I put together this js file that I load just after loading the accordionmenu.js file. Then all I have to do is link to my faq page using something in this form: example.com/faq.html?id=li_id

I works great! Bulk of code below taken from 3rd edition David Flanagan's "JavaScript - The Definitive Guide".

/*

 * script to take query string of form ?id=something and force

 * accordion menu to open to the indicated id.

 */


/* function to parse the query string into name=value pairs */


function getArgs() {

   var args= new Object();

   var query = location.search.substring(1); // get query string

   var pairs = query.split(",");             // break at commas

   for(var i = 0; i < pairs.length; i++) {

      var pos = pairs[i].indexOf('=');       // look for name=value

      if (pos == -1) continue;               // not here, skip

      var argname = pairs[i].substring(0,pos); // otherwise, extract the name

      var value = pairs[i].substring(pos+1); // and then the value

      args[argname] = unescape(value);       // store in our new Object

   }

   return args;                              // and send it back to caller

}


var args = getArgs();                        // get the arguments

if (args.id) amenu.open(args.id.toString(), true); // open item if specified 

Dennis Nichols  9 years ago   viewed: 3346    

   

Your name*
Password
(Optional. Used to modify this post afterwords)
+ =  

Ask your Own Question

  • If your question is related to the topic of this post, you can post your question to this page by clicking the "Post a reply" button at left;

  • When you want to start a new page for your question: