Warm tip: This article is reproduced from serverfault.com, please click

html-iframe中的图片(javascript,传单)上的超链接

(html - hyperlink on a image which is in a iframe (javascript, leaflet))

发布于 2020-11-30 13:17:35

我显示一个带有弹出窗口的标记。弹出窗口显示图像。
如果用户单击图像,我想打开一个网站。
我是这样做的:

Popup = "<div><a href='http:...'><iframe src='" +  m.image + "' scrolling='no' frameBorder='0' style='border:none;' ></iframe></a></div>";
marker.bindPopup(Popup).openPopup();

当我在图像上鼠标移动时,我有一个缩放图标(应该是一个手形图标)。
如果我单击图像,则该图像将被放大。

你看到我的错误了吗?

注意#1:我设置了自定义className的样式(从另一个问题中复制):

<style>
 .custom-popup .leaflet-popup-content-wrapper {
  background:#2c3e50;
  color:#fff;
  font-size:16px;
  line-height:24px;
  }
.custom-popup .leaflet-popup-content-wrapper a {
  color:rgba(255,255,255,0.5);
  }
.custom-popup .leaflet-popup-tip-container {
  width:30px;
  height:15px;
  }
.custom-popup .leaflet-popup-tip {
  border-left:15px solid transparent;
  border-right:15px solid transparent;
  border-top:15px solid #2c3e50;
 }   
</style>

我定义了选项:

var options =
    {
        'maxWidth': '400',
        'width' : '300',
        'className': 'custom-popup'
    }

最后创建弹出窗口:

Popup+= "<div><a href='https://google.com'><img src='" +  (BASE_URL || '') + m.image + "' /></a></div>";
result.bindPopup(potentialPopup,options).openPopup();

颜色会发生变化,但弹出窗口的大小不会发生变化,并且图像非常小???

小叶弹出内容包装器91x62
小叶弹出内容包装器51x34

注意#2:我添加了以下样式:

img {
    height:350px;
    width:700px;
}

并更改了选项:

var options =
    {
        //'maxWidth': '400',
        //'width' : '300',
        'className': 'custom-popup'
    }

并且...弹出窗口/图像的高度已更改!但不是宽度?

注意#3:这是解决方案

.custom-popup div.leaflet-popup-content {
  min-Width: 300px;
  max-Width: 300px;
}

不要问为什么!
谢谢@mplungjan的帮助!

Questioner
jpc
Viewed
0
mplungjan 2020-12-01 22:10:52

请勿将iFrame包裹在锚点中,因为它不是有效的HTML,也不会链接iFrame的内容。

div和achor会根据内容调整其大小:

const m = { image: "https://i.imgur.com/k5QOP26.jpeg" }
const popup = "<div><a href='https://...'><img src='" + m.image + "'/></a></div>";
document.body.innerHTML += popup;
/* css 1 */
img { height: 50px }

/* css 2 */
img { height: 350px }