来自iFrame的Colorbox加载特定div [英] Colorbox Load Specific div from iFrame

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

问题描述

我正在使用Colorbox,并且我想从网站上的其他页面加载特定的div.现在,我正在使用iFrame,但我猜不一定是iFrame,因为我住在同一网站上.我现在的代码是:

I'm using Colorbox, and I want to load a specific div from another page on the website. Right now I'm using an iFrame, but I guess it doesn't necessarily have to be an iFrame, since I'm staying on the same website. My code right now is:

$(document).ready(function(){
  $(".iframe").colorbox({iframe:true, data:"#mainColumn", width:"80%", height:"80%"});
});

<a class="iframe cboxIframe" href="http://website.com/products-51>.html">

我需要将href中的页面加载到Colorbox中,但仅显示#mainColumn div.

I need to load the page in the href into the Colorbox, but only display the #mainColumn div.

推荐答案

ColorBox利用jQuery的.load()方法来处理ajax.如果要从与当前文档相同的域中加载文档,则可以使用选择器仅拉出所需文档的一部分.我假设您要从其他页面获取的容器是#mainColumn

ColorBox leverages jQuery's .load() method for handling ajax. If you are loading a document from the same domain as your current document, you can use a selector pull out just the portion of the document that is needed. I am assuming the container which you want from other page is #mainColumn

var $iframe = $(".iframe");
$(".iframe").colorbox({ 
    href: $(".iframe").attr('href') + " #mainColumn",
});

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

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