Lightbox 2删除数据标题中的target =“_blank”行为 [英] Lightbox 2 removes target="_blank"'s behavior in data-title

查看:86
本文介绍了Lightbox 2删除数据标题中的target =“_blank”行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Lightbox的标题功能作为放置PDF下载链接和网站网址的简单方法,以便人们能够详细了解设计并实际访问他们视为图像的互动网站。我这样做:

 < a href =projects / img_full / my_project.pngdata-lightbox =project1 data-title =< a href ='http://example.com/'target ='_ blank'>访问网站< / a>> 
< img src =projects / thumbs / my_project.pngalt =Project 1/>
< / a>

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



为什么会发生这种情况?有没有办法避免它?

解决方案

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

我在Lightbox库中找到了一些我认为负责运行网址的内容

  //在页面中启用锚点击注入标题html。 
//感谢Nate Wright的修复。 @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)$ b $ (''')。on('click',function(event){
if($(this).attr('target')!= =未定义){
window.open($(this).attr('href'),$(this).attr('target'));
} else {
location.href = $(this).attr('href');
}
});
}


I'm trying to use Lightbox's title function as a simple way to put PDF download links and website URLs so that people are able to see designs in full detail and actually visit interactive websites they've seen as images. I do it this way:

<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>

The link outputs correctly under the Lightbox's image, and target='_blank' remains if I inspect it in my browser. However, the link still opens in the same tab.

Why does this happen? Is there a way to avoid it?

解决方案

I have the same problem, on my project page I have gallery of places, and in title I have an url to wiki site with description of current place, when I click on the link page opens in the same window, in firebug everything looks fine (with attribute target etc.)

I found something in Lightbox library that I think is responsible for running urls

  // 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');
      });
  }

but I'm not 100% sure that is this, could someone show where I can update code and depened opening links by the "target" attribute?

EDIT:

ok, found solution to this, need to replace code above with this and it works for me, found it on 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');
                }
            });
        }

这篇关于Lightbox 2删除数据标题中的target =“_blank”行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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