首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jquery colorbox:关闭colorbox后获取参数

jquery colorbox:关闭colorbox后获取参数
EN

Stack Overflow用户
提问于 2011-03-07 13:33:44
回答 1查看 3.7K关注 0票数 2

我有像下面这样的父页面parent.html来调用colorbox:

代码语言:javascript
复制
 <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上,我有两张图片

代码语言:javascript
复制
 <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获取参数

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-06 16:52:17

您可以使用自己的函数覆盖Colorbox的close函数。

代码语言:javascript
复制
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方法。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5216203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档