jQuery Colorbox iframe和选择器 [英] jQuery Colorbox Iframe and Selector
问题描述
我有这个:
$("a.money").colorbox({href:$("a.money").attr("href")+" div#content"});
将打开一个叠加层,但仅打开#content选择器中的内容.如果我添加iframe:true,它将不再起作用.有没有办法让它与iframe一起使用?
Which opens an overlay but only of the content within the #content selector. If I add iframe:true, this will no longer work. Is there a way to get it to work with an iframe?
修改: 我最能使它正常工作的是这样做:
The closest I could get it to work was by doing this:
$("a.money").colorbox({iframe:true, width:700, height:425,
onComplete: function() {
alert('test');
$test = $("#cboxLoadedContent iframe").contents().find("#content").html();
$("#cboxLoadedContent iframe").contents().find("#container").html($test);
}
});
尽管没有警报,它似乎也不起作用,但我调查了一下,我认为我需要使用.live(),这促使我尝试了此操作:
Although without the alert it doesn't appear to work, I looked into that and I think I need to use .live(), which led me to trying this:
$('a.money').live('click', function() {
url = this.href; // this is the url of the element event is triggered from
$.fn.colorbox({href: url, iframe:true,width:700, height:425,
onComplete: function() {
$test = $("#cboxLoadedContent iframe").contents().find("#content").html();
$("#cboxLoadedContent iframe").contents().find("#container").html($test);
}
});
return false;
});
没有用,我仍然需要添加警报以使其起作用.
Didn't work, I still needed to add an alert to make it work.
以防您可能想知道我要做什么.该网页已加载到iframe中,所有元素都包含在#container中,因此其中包括#header,#sidebars,但是我只想显示iframe中的#content.但是,这导致了我意识到的另一个问题.假设我在没有警报的情况下正常工作,那么它将仅适用于该初始页面.例如,如果我在iframe中加载了表单,则在提交表单后,我将再次看到整个布局,而不仅仅是#content部分.是否可以在进一步导航时继续仅显示页面的#content部分?
In case you might be wondering what I'm trying to do. The webpage is loaded in the iframe, with all the elements in the #container, so that includes #header, #sidebars, but I only want to show the #content inside the iframe. However, this led me to another problem I realized. Assuming I got this to work without the alert, it will only work for that initial page. For example, if I loaded up a form in the iframe, after submitting the form, I would once again see the whole layout instead of just the #content portion. Is it possible to continue only showing the #content portion of the page upon further navigation?
推荐答案
我根据这些线程中找到的代码找到了另一种解决方案:
I found an alternative solution as per the code found in these threads:
http://groups.google.com/group/colorbox/Browse_thread/thread/9a54137b8cae96c5/11d37ea7ab72562f http://groups.google.com/group/colorbox/browse_thread/thread/8a0deec97202e27c/2e7524b87931a89e
http://groups.google.com/group/colorbox/browse_thread/thread/9a54137b8cae96c5/11d37ea7ab72562f http://groups.google.com/group/colorbox/browse_thread/thread/8a0deec97202e27c/2e7524b87931a89e
它不使用iframe,或多或少正是我想要的.
It doesn't use iframe, but it's more or less the exactly what I wanted.
这篇关于jQuery Colorbox iframe和选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!