Colorbox iframe - 仅加载特定div [英] Colorbox iframe - loading specific div only

查看:99
本文介绍了Colorbox iframe - 仅加载特定div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用wordpress和jquery colorbox插件,我正在从我的网站加载内部页面到iframe。我想要只加载一个特定的div ID,或者隐藏特定的div ID或类。我已经阅读了来自iFrame的Colorbox Load Specific div ,但不幸的是我不是能够使此代码工作,整个页面继续显示在iframe中。我的链接用类.colorbox-link标识,我试图只在iframe中显示#main的div。这是我在header.php中放置的当前代码:

I'm using wordpress and the jquery colorbox plugin, and I'm loading an internal page from my website into an iframe. I'd like to either only load a specific div ID or, alternatively, hide specific div IDs or classes. I've read Colorbox Load Specific div from iFrame but unfortunately I'm not able to get this code to work, the entire page continues to display in the iframe. My links are identified with the class .colorbox-link and I'm trying to only display the div of #main inside the iframe. Here's my current code that I've placed in header.php:

<script type="text/javascript">
    $(window).load(function () {
        var $iframe = $(".colorbox-link"); 
        $(".colorbox-link").colorbox({      
             href: $(".colorbox-link").attr('href') + " #main", 
        }); 
    }); 
</script>

很抱歉,如果这是一个jquery新手问题 - 提前感谢您的帮助!

Sorry if this is a jquery newbie question - thanks in advance for any help!

推荐答案

在这种情况下,颜色框不会在iframe中显示任何内容。 iframe不是colorbox所假设的,你必须将colorbox的iframe属性显式设置为true才能在iframe中显示某些内容。无论如何,这不是你想要做的事情。

Well colorbox wouldn't be displaying anything in an iframe in this situation. Iframe's aren't something that colorbox assumes, you would had to have to explicitly set colorbox's iframe property to true to display something in an iframe. It's not something you want to do in this situation anyway.

您发布的代码应该有效(在逗号之外),所以也许您应该发布一个链接来证明您遇到的问题。还要仔细检查'#main'是否与您要加载的文档中的元素匹配。

The code you posted should work (outside of that stray comma), so maybe you should post a link demonstrating the problem you having. Also double check that '#main' matches an element in the document you are loading.

<script type="text/javascript">
    $(window).load(function () {
        $(".colorbox-link").colorbox({      
             href: function(){ return $(this).attr('href') + " #main";}
        }); 
    }); 
</script>

这篇关于Colorbox iframe - 仅加载特定div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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