Html 使图像链接可在新选项卡中打开
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11639335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Make Image Link Openable In New Tab
提问by geogaddi
I have the following HTML template :
我有以下 HTML 模板:
<div class='item'>
<img href='...' attributes='...' \>
<div class='popup' attributes='...'>
</div>
</div>
I use Jquery to on mouse over of the div (and thus the image), and show the popup. The problem is, I can't seem to control+click to open in a new tab in chrome nor firefox; neither can I right click the image and open the link in a new tab. How can I do this?
我使用 Jquery 将鼠标悬停在 div(以及图像)上,并显示弹出窗口。问题是,我似乎无法控制+单击以在 chrome 或 firefox 的新标签页中打开;我也不能右键单击图像并在新选项卡中打开链接。我怎样才能做到这一点?
回答by Nathan
Add target="_blank"
to the link. It should look something like this:
添加target="_blank"
到链接。它应该是这样的:
<div class='item'>
<a href='...' target="_blank"><img src='....' attributes='...' \></a>
<div class='popup' attributes='...'>
</div>
</div>
The link that you want the image to open goes in a href='LINK'
and the file path to the image goes in img src='PATH'
你希望图片打开的链接进去a href='LINK'
,图片的文件路径进去img src='PATH'
回答by Luis
Here's the code markup with an example of an image (ctrl+click on it and it will take you to google.com):
这是带有图像示例的代码标记(ctrl+单击它,它将带您到 google.com):
<div class="item">
<a href="http://www.google.com">
<img src="https://www.google.com/intl/en_ALL/images/logos/images_logo_lg.gif" attributes="#"\>
</a>
<div class="popup" attributes="#">
</div>
</div>
You just needed to wrap your <img>
tag with an <a>
tag.
您只需<img>
要用<a>
标签包装您的标签。
Hope it helps!
希望能帮助到你!
回答by Jeff
All you need is
所有你需要的是
<div class='item' >
<a href='...' attributes='...' target="_parent">
<img src="yoursource.jpg"/></a>
<div class='popup' attributes='...'>
</div>
</div>
Add target="_parent" or you could use _blank to your href (and remove the img for now), then close the href with > and make and new img field. wrap your href and img with Should work now
添加 target="_parent" 或者您可以使用 _blank 到您的 href (并暂时删除 img),然后使用 > 关闭 href 并创建和新建 img 字段。将您的 href 和 img 包裹起来,现在应该可以工作了
回答by dezman
Surround your image with <a>
tags and link to a new page which has the image on it.
用<a>
标签包围您的图像并链接到包含图像的新页面。