【问题标题】:Colorbox reload parent page on closeColorbox 在关闭时重新加载父页面
【发布时间】:2011-04-19 11:11:16
【问题描述】:

我的问题是我需要一个颜色框来在关闭时重新加载父页面。

这就是我所拥有的:

$(".example").colorbox({
    onClosed:function(){
        parent.location.reload();
    }
});

Colorbox 加载正常,但关闭时不会刷新父页面。有什么想法吗?

【问题讨论】:

  • 别忘了接受答案。

标签: jquery colorbox


【解决方案1】:

使用window.location.reload(); 或window.location = window.location; 代替parent.location.reload();

【讨论】:

    【解决方案2】:

    有点延迟,但我有另一个答案。您可以发送代码以从在颜色框中加载的目标页面重新加载窗口。

    我将颜色框用于登录/how_it_works/faqs 和其他一些功能。我希望我的父页面仅在“登录”的情况下重新加载。因此,为了响应登录表单,我发送了以下代码:

    <script type="text/javascript">
     window.parent.location.reload();
    </script>
    

    'window' 是彩盒窗口。我要求它的父级(浏览器窗口)重新加载。

    【讨论】:

      【解决方案3】:

      或者直接使用

      <input type="submit" onclick="parent.location.reload()" value="Save" name="submit"/>
      

      我更喜欢这个而不是 Lucas 的解决方案,因为您也可以轻松创建

      <input type="button" onclick="javascript:parent.$.colorbox.close()" value="Cancel" />
      

      无需重新加载整个页面。

      【讨论】:

        【解决方案4】:

        这是我的通用颜色框打开功能:

        它可以:

        • 关闭后重新加载页面
        • 自行重新加载(+ 使用一些自定义 Ajax URL)
        • 加载另一个 HTML
        • 重要 -> 当您手动关闭彩盒时会发生这些操作:
          • 适当设置全局变量
          • $.colorbox.close();

        还有:

        • 加载后聚焦自定义 HTML 元素

        重点是,您应该拥有(当然,如果您知道自己在做什么)一些 GLOBAL JavaScript 变量,仅此而已。

        function showActionForColorBox(
           _url,
           _forFocus
           ) {
           _url = fixURLWithMasterServerPrefix(_url);
           $.colorbox(
                 {
                    scrolling: false,
                    href: _url,
                    onLoad: function () {
                       idColorboxAjaxIndect1.appendTo($('#cboxOverlay'));
                       idColorboxAjaxIndect2.appendTo($('#cboxOverlay'));
                       idColorboxAjaxIndect3.appendTo($('#cboxOverlay'));
                       idColorboxAjaxIndect4.appendTo($('#cboxOverlay'));
                       return;
                    },
                    onComplete: function () {
                       if (_forFocus) {
                          var c = $('#' + _forFocus);
                          if (c.length) {
                             c.focus();
                          }
                       }
                       return;
                    },
                    onCleanup: function () {
                       // TODO: ?
                       return;
                    },
                    onClosed: function () {
                       abortAllAsyncAjaxRequests();
        
                       if (shouldReloadPageAfterColorBoxAction) {
                          shouldReloadPageAfterColorBoxAction = false; // NOTE: To be sure: Reset.
                          reloadWholePage();
                       }
                       else if (cbEBillsActionReloadPopup) {
                          cbEBillsActionReloadPopup = false;
                          // NOTE: WE HAVE AN OPTION TO RELOAD COLORBOX WITH CUSTOM URL !
                          showActionForColorBox((cbActionReloadPopupCustomURL !== '' ? cbActionReloadPopupCustomURL : _url));
                          cbActionReloadPopupCustomURL = '';
                       }
                       else if (cbShouldLoadAnotherContentAfterClosed) {
                          cbShouldLoadAnotherContentAfterClosed = false;
                          $.colorbox({ html: setupContentForcbShouldLoadAnotherContentAfterClosed });
                          setupContentForcbShouldLoadAnotherContentAfterClosed = '';
                       }
                       return;
                    }
                 }
                 );
        
           return;
        }
        

        【讨论】:

          【解决方案5】:
          $(document).bind('cbox_closed', function(){
              location.reload();
          });
          

          以上代码用于彩盒默认关闭 (x) 按钮。

          如果你有自己的关闭按钮,那么试试这样:

          $('#id').click(function(){
              location.reload();
          });
          

          【讨论】:

            【解决方案6】:
            function __colorbox_onClose(e) {
                $.fn.colorbox.close();
                return false;
            }
            $.fn.colorbox.close(); - Closes colorbox manually
            
            return false; - reloads/Autopostbac's form from which you called colorbox
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2013-09-15
              • 1970-01-01
              • 2012-07-09
              • 1970-01-01
              相关资源
              最近更新 更多