任何URL的Colorbox模态

Colorbox modal of any URL

本文关键字:模态 Colorbox URL 任何      更新时间:2023-09-26

我试图创建一个模式,打开任何URL,其中a标签有一个特定的类。

在colorbox文档中有这样一个例子:

// ColorBox can accept a function in place of a static value:
$("a.gallery").colorbox({rel: 'gal', title: function(){
  var url = $(this).attr('href');
  return '<a href="' + url + '" target="_blank">Open In New Window</a>';
}});
我的HTML结构是:

" class="modal" rel="gal">

        <h2 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h2>
        <div class="entry">
            <?php the_excerpt(); ?>
        </div>
</div>

和我的JS是:

jQuery(".modal").colorbox({rel: 'gal', title: function(){
  var url = jQuery(this).attr('href');
  return '<a href="' + url + '" target="_blank">Open In New Window</a>';
}});

但它只是没有触发-我没有得到任何控制台JS错误-有人能看到这里有什么问题吗?

您正在对<div>元素使用colorbox()方法,这不是该方法的有效元素。此方法只能用于<a>元素。

完全误解了这个功能——如果你想做我在开头的文章中概述的事情,那么使用iframe功能。

jQuery(function () {
    jQuery(".modal").colorbox({iframe:true, innerWidth:425, innerHeight:344});    
})

parent.$.colorbox。