FancyBox iframe返回parent。$ as undefined(使用WordPress) [英] FancyBox iframe returns parent.$ as undefined (using WordPress)

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

问题描述

我正在尝试从iframe中关闭 FancyBox ,但是 parent。$ 总是 undefined
这是我的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);
$('#取消')。closeFancyBox();
});
});
< / script>

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



我正在使用WordPress 2.9.1,带有FancyBox for Wordpress插件。




  • main page: // server.local / web / test / index.php

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



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



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

解决方案

花了几个小时试图调试它并且无处可去。 所以我用最新版本的FancyBox切换了'FancyBox for WordPress'插件,并且修复了。之前真的应该尝试过。



<在花了一些时间使用WordPress及其各种插件后,我建议手动调用而不是依赖插件。它只是增加了另一层复杂性,如果你知道你在做什么,就不需要在那里。



感谢Doug指出适当的语法对于WordPress中的iframe到父窗口jQuery。


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>

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.

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

  • main page: //server.local/web/test/index.php
  • iframe page: //server.local/web/test/wp-content/plugins/wp-test/test.htm

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.

解决方案

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.

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.

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

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

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