FancyBox iframe 将 parent.$ 返回为未定义(使用 WordPress) [英] FancyBox iframe returns parent.$ as undefined (using WordPress)

查看:17
本文介绍了FancyBox iframe 将 parent.$ 返回为未定义(使用 WordPress)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 iframe 中关闭 FancyBox,但是 parent.$总是 undefined.这是我的 iframe JavaScript:

I'm trying to close FancyBox from within the iframe, but parent.$ is always undefined. This is my iframe JavaScript:

 <script type='text/javascript' 
  src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'>
 </script>
 <script type="text/javascript">
 jQuery(document).ready(function($){
     (function($) {
         $.fn.closeFancyBox = function() {
             $(this).click(function() {
                 parent.$.fancybox.close();
             });
         };
      })(jQuery);
      $('#cancel').closeFancyBox();
      });
 });
 </script>

alert('clicked'); 替换 parent.$.fancybox.close(); 效果很好.当 iframe 在同一个域中时,我不明白为什么 parent.$undefined.

Replacing parent.$.fancybox.close(); with alert('clicked'); works just fine. I don't understand why parent.$ is undefined when the iframe is in the same domain.

我使用的是 WordPress 2.9.1 和 FancyBox for Wordpress 插件.

I'm using WordPress 2.9.1, with the FancyBox for Wordpress plugin.

  • 主页://server.local/web/test/index.php
  • iframe 页面://server.local/web/test/wp-content/plugins/wp-test/test.htm

这些url中的第一个是主页,第二个是iframe页面;server.local 是我的家庭测试服务器.

The first of these urls is the main page, the second is the iframe page; server.local is my home test server.

有什么想法吗?如果有帮助,我可以粘贴整个源代码.

Any ideas? I can pastebin the entire source if it would be helpful.

推荐答案

花了好几个小时试图调试这个,但一无所获.所以我用最新版本的 FancyBox 换掉了FancyBox for WordPress"插件,它得到了修复.真的应该早点尝试.

Spent quite a few hours trying to debug this and got nowhere. So I switched out the 'FancyBox for WordPress' plugin with the latest version of FancyBox, and it was fixed. Really should have tried that earlier.

在使用 WordPress 及其各种插件一段时间后,我建议手动调用而不是依赖插件.它只是增加了另一层复杂性,如果您知道自己在做什么,则不需要在那里.

After having spent some time with WordPress and its various plugins, I'd recommend calling things manually rather relying on plugins. It just adds another layer of complexity that, if you know what you're doing, doesn't need to be there.

感谢 Doug 指出 WordPress 中 iframe 到父窗口 jQ​​uery 的适当语法.

Thanks to Doug for pointing out the appropriate syntax for iframe to parent window jQuery in WordPress.

这篇关于FancyBox iframe 将 parent.$ 返回为未定义(使用 WordPress)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆