【问题标题】:Lightbox 2 removes target="_blank"'s behavior in data-titleLightbox 2 删除了 data-title 中 target="_blank" 的行为
【发布时间】:2014-11-03 04:52:49
【问题描述】:

我正在尝试使用 Lightbox 的标题功能作为放置 PDF 下载链接和网站 URL 的简单方法,以便人们能够查看设计的全部细节并实际访问他们所看到的交互式网站作为图像。我是这样做的:

<a href="projects/img_full/my_project.png" data-lightbox="project1" data-title="<a href='http://example.com/' target='_blank'>Visit site</a>">
    <img src="projects/thumbs/my_project.png" alt="Project 1" />
</a>

链接在灯箱图像下正确输出,如果我在浏览器中检查它,target='_blank' 仍然存在。但是,链接仍会在同一标签中打开

为什么会这样?有办法避免吗?

【问题讨论】:

    标签: html tabs lightbox2


    【解决方案1】:

    我有同样的问题,在我的项目页面上我有地方画廊,并且在标题中我有一个 wiki 站点的 url,其中包含当前位置的描述,当我点击链接页面时,在同一窗口中打开,在 firebug一切看起来都很好(带有属性目标等)

    我在 Lightbox 库中发现了一些我认为负责运行 url 的东西

      // Enable anchor clicks in the injected caption html.
      // Thanks Nate Wright for the fix. @https://github.com/NateWr
      if (typeof this.album[this.currentImageIndex].title !== 'undefined' && this.album[this.currentImageIndex].title !== "") {
        this.$lightbox.find('.lb-caption')
          .html(this.album[this.currentImageIndex].title)
          .fadeIn('fast')
          .find('a').on('click', function(event){
            location.href = $(this).attr('href');
          });
      }
    

    但我不能 100% 确定是这样,有人可以告诉我在哪里可以通过“目标”属性更新代码和依赖打开链接吗?

    编辑:

    好的,找到了解决方案,需要用这个替换上面的代码,它对我有用,在 github 上找到 https://github.com/lokesh/lightbox2/pull/299/files

    if (typeof this.album[this.currentImageIndex].title !== 'undefined' && this.album[this.currentImageIndex].title !== "") {
                this.$lightbox.find('.lb-caption')
                        .html(this.album[this.currentImageIndex].title)
                        .fadeIn('fast')
                        .find('a').on('click', function (event) {
                    if ($(this).attr('target') !== undefined) {
                        window.open($(this).attr('href'), $(this).attr('target'));
                    } else {
                        location.href = $(this).attr('href');
                    }
                });
            }
    

    【讨论】:

    • 一个问题仍然存在:使用window.open() 打开一个新标签会导致它被浏览器阻止为弹出窗口。我想知道是否有其他方法可以做到这一点。
    • 为我工作!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-21
    • 1970-01-01
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多