我正在使用Fancybox (http://fancybox.net) 来弹出一个iFrame。为了实现这一点,我创建了一个类名为“item_pop”的链接,如下所示:
<div id="events">
<a href="http://www.example.com" class="item_pop">My Link</a>
</div>
我在页脚中添加了一些JavaScript来支持此功能:
jQuery(".item_pop").fancybox({
'width' : 900,
'height' : 500,
'autoDimensions' : true,
'autoScale' : true,
'transitionIn' : 'elastic',
'titleShow' : false,
'transitionOut' : 'elastic',
'centerOnScroll' : true,
'type' : 'iframe'
});
好的,这一切都很顺利。问题是我使用jQuery动态创建了额外的链接,就像这样:
jQuery(document).ready(function(){
update_seconds = 20;
update_duration = update_seconds * 1000;
window.setInterval(reload_events, update_duration);
});
function reload_events()
{
jQuery.post("http://www.example.com", {type:'any'}, function(data){
var events = eval(data);
var html = '';
for(var i=0; i<events.length; i++){
var evt = events[i];
html += '<a href="http://www.example.com" class="item_pop">My Link</a>';
}
jQuery('#events').children().remove();
jQuery('#events').append(html);
});
}
实际上,这会在屏幕上显示链接,但当您单击它们时,它们不会弹出iFrame。相反,它们会将预期页面作为新页面打开,而不是作为现有页面中的iFrame。
有什么想法吗?谢谢。