2011-03-07 76 views
2

后,我有parent.html父页下面一样调用颜色框:jQuery的颜色框:获取参数密切颜色框

<script src="colorbox/jquery.min.js"></script> 
<script src="colorbox/jquery.colorbox.js"></script> 
<script> 
    $(document).ready(function(){ 

     $(".example7").colorbox({ 
      width:"60%", 
      height:"40%", 
      iframe:true 
      }); 

     //How I can get Parameters from ColorBox when ColorBox closed 
</script> 

<body> 
    <p><a class='example7' href="demo_01.html">Click here to open Colorbox</a></p> 
</body> 

而且在demo_01.html,我有2个图像

<html> 
<script type="text/javascript"> 
function onChooseAndClose(val){ 
     //how to setup to sent paramters (ID of image was chosen) to parent page before close colorbox 
     ...... 
     //close this Colorbox 
     parent.$.fn.colorbox.close() 

    } 
</script> 
<body> 
    <img src="imamges/img1.png" id="idImg1" onclick="javascript:onChooseAndClose('idImg1');" /> 
    <img src="imamges/img2.png" id="idImg2" onclick="javascript:onChooseAndClose('idImg2');" /> 

</body> 
</html> 

在parent.html ,如何在ColorBox关闭时从ColorBox获取参数

谢谢。

回答

3

您可以使用自己的功能覆盖Colorbox的关闭功能。

var originalClose = $.colorbox.close; 
$.colorbox.close = function(){ 
    var response; 
    if($('#cboxLoadedContent').find('form').length > 0){ 
     response = confirm('Do you want to close this window?'); 
     if(!response){ 
      return; // Do nothing. 
     } 
    } 
    originalClose(); 
}; 

这里我们得到原始的close方法。 而且我们重写该方法来完成我们的脚本,最后我们调用原始的Close方法。