jquery colorbox: получить параметры после закрытия colorbox - PullRequest
2 голосов
/ 07 марта 2011

У меня есть родительская страница parent.html, как показано ниже для вызова colorbox:

 <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>

In parent.htmlКак я могу получить параметры из ColorBox когда ColorBox закрыт

Спасибо.

1 Ответ

3 голосов
/ 06 мая 2011

Вы можете переопределить функцию закрытия 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.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...