开发者

How to show ColorBox Dialog when URL Parameter is passed in jQuery

I'm looking to show a ColorBox Dialog, using the开发者_如何学JAVA code

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

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


I use this when i want to open colorboxes thru code

$.fn.colorbox({href:'#delete-comment-div', open:true, inline:true});

Where delete-comment-div is the id of the div i would like to show (In my site it is nested in a hidden div).


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();
});


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();
  }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜