views:

299

answers:

2

I'm looking to show a ColorBox Dialog, using the code

$(document).ready(function() $(".colorbox_dialog").colorbox(); });

When the url parameter ?dialog=yes is passed. How can I do this in jQuery 1.3+?

A: 
window.location.getQueryString = function(queryStringName) { //usage - var blah = location.getQueryString("queryStringName");
        var qStrings = this.search.substring(1).split("&");
        for (var i=0;i<qStrings.length;i++)
        {
            var pair = qStrings[i].split("=");
            if (pair[0] == queryStringName) return decodeURIComponent(pair[1].replace(/\+/g, " ")); //str = str.replace(/find/g,”replace”)
        }
        return null;
      }

$(document).ready(function() {
  var dialog = location.getQueryString("dialog");
  if (dialog == "yes") $(".colorbox_dialog").colorbox({open:true});
  else $(".colorbox_dialog").colorbox();
});
Bradley Mountford
A: 

Add the extend code from http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html to your Javascript. Then change the code above to:

$(document).ready(function() {
  if ($.getUrlVar('dialog') === 'yes') {
    $(".colorbox_dialog").colorbox();
  }
});
Peter Jaric