【问题标题】:Calling colorbox close from iframe从 iframe 调用 colorbox 关闭
【发布时间】:2013-03-19 17:16:41
【问题描述】:

我正在尝试从 iframe 调用 colorbox close() 函数。这就是我所拥有的。

主页

    <script>
        $(document).ready(function(){
            $("#click").colorbox({width:"60%",
                        height:"60%",
                        iframe:true

            });
        });
    </script>

     <a href="login.html" id="click">Click Me!</a>

登录.html

     <!DOCTYPE html>
     <html>
          <head>
         <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
          <script src="jquery.colorbox.js"></script>
    <script>
        $(document).ready(function(){
            setTimeout(function() {
                parent.jQuery.fn.colorbox.close();
            }, 3000);
        });
    </script>
    </head><body></body>
</html>

调用 settimeout 时出现此错误。

未捕获的类型错误:无法读取未定义的属性“fn”

我试图按照这个帖子中的答案。 how to close colorbox within iframe?

【问题讨论】:

  • 尝试仅删除 .fn parent.jQuery.colorbox.close();
  • '无法读取未定义的属性颜色框'
  • 您是否引用过colorbox 脚本...?
  • @Dom.. 是的,我愿意。我在这里手动输入代码,这就是它丢失的原因。编辑了问题。即便如此,这也不是彩盒的问题。 “父母”本身发生了一些奇怪的事情。我试过用 Chrome 查看“父级”内部的内容,但它是空的。有没有办法打印“父母”的内容?这可能有助于确定问题。

标签: jquery iframe colorbox


【解决方案1】:

我们可以使用

parent.jQuery.fn.colorbox.close();

效果很好

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多