Style Sheet Switcher (v1.1) based on QueryString Parameter

I am using the stylesheet switcher on dynamic drive . Is there a way to change stylesheets based on a querystring parameter? Basically, if the query string includes “&StyleSheet=BlueStyle” then call and set the BlueStyle.css and cookie on page load.

Any ideas or help would be much appreciated. Thanks!!

Absolutely, you could use a function like the below:


function getUrlParam(name){
  var results = new RegExp('[\\\\?&]' + name + '=([^&#]*)').exec(window.location.href);

  if (!results) { return 0; }
  return results[1] || 0;

}

var newStyle = getUrlParam("stylesheet");
chooseStyle(newStyle, 60) 

(This is a slight adaptation of a snippet I have in snipplr somewhere)

How do I implement this in the current JS? Sorry I am new at this. Thanks for any feedback.