Get URL Parameters using jQuery
-
Love this calendar widget plugin, hope the following may help someone someday. So not a question, just a problem I solved with the help of StackOverflow. So we have the Mini calendar widget (with data linking to a jQuery pop-up view) nested within a custom accordion-module and initially hidden but revealed when clicking on the header with arrow. Problem we were facing was the page-refresh when having the widget active, let’s say clicking on the widget arrow navigating to previous or next month, … and the widget would be hidden again after the page-refresh. The way this was solved is with the URL-parameter (, which is the part after the question-mark in the url of the page after the next or previous month arrow was clicked): something like
?yr=2016&month=12&dy=&cid=mc_mini_widget-2
. Now with jQuery javascript we can add a class ofmc_mini_widget-2
to thebody
-tag like this:var getUrlParameter = function getUrlParameter(sParam) { var sPageURL = decodeURIComponent(window.location.search.substring(1)), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : sParameterName[1]; } } }; var cid = getUrlParameter('cid'); $('body').addClass(cid);
This class can than be used in the CSS stylesheet to keep our custom accordion-module visible.
- The topic ‘Get URL Parameters using jQuery’ is closed to new replies.