使用 fancybox 时谷歌地图在新窗口中显示图像的问题
在显示 KML 文件的内容时,我遇到了 fancybox 和 google 地图(v3)方面的一些问题。
当显示包含描述的气球时,我有一个图像的缩略图,我想在使用 fancybox 单击时显示该图像的缩略图。我遇到的问题是,当单击缩略图时,会显示 fancybox,但浏览器还会生成一个显示全尺寸图像的新窗口。
我知道在解析 KML 文件时,任何 href 标签都会添加目标属性,因此我尝试在地图加载后将其删除,同时将 fancybox 附加到链接。
我确保在尝试之前地图已加载:即
function updatemap(surveyid){
var map;
var myOptions = {
zoom: 5,
mapTypeId: google.maps.MapTypeId.HYBRID
};
var url = "https://myurl/feed/kml.php?action=survey&id=" + surveyid;
map = new google.maps.Map(document.getElementById("googlemap"), myOptions);
var kmlLayer = new google.maps.KmlLayer(url);
kmlLayer.setMap(map);
google.maps.event.addListener(map, "tilesloaded", function(){
attachFancyBox();
});
}
attachFancyBox() 函数如下所示。
function attachFancyBox(){
$("a:has(img)").fancybox({
"hideOnContentClick":true
}).removeAttr("target");
}
现在这将适用于 Firefox,但其他浏览器(IE7+、safari、chrome)的行为如上面提到的。那么有没有一种方法可以实现在 fancybox 中显示图像而不生成新窗口/选项卡?
非常感谢...
I am having a few issues with fancybox and google maps(v3) when displaying the contents of a KML file.
When displaying the balloon that contains the description, I have a thumbnail of an image that I want to display when clicked using fancybox. The problem I have is that when the thumbnail is clicked the the fancybox displays but the browser also spawns a new window displaying the full size image.
I know that when the KML file is parsed any href tags have the target attribute added, so I've tried to remove it once the map has loaded, during the same time I attach the fancybox to the link.
I ensure that the map has loaded before I try: i.e.
function updatemap(surveyid){
var map;
var myOptions = {
zoom: 5,
mapTypeId: google.maps.MapTypeId.HYBRID
};
var url = "https://myurl/feed/kml.php?action=survey&id=" + surveyid;
map = new google.maps.Map(document.getElementById("googlemap"), myOptions);
var kmlLayer = new google.maps.KmlLayer(url);
kmlLayer.setMap(map);
google.maps.event.addListener(map, "tilesloaded", function(){
attachFancyBox();
});
}
The attachFancyBox() function looks like this.
function attachFancyBox(){
$("a:has(img)").fancybox({
"hideOnContentClick":true
}).removeAttr("target");
}
Now this will work with firefox however other browsers (IE7+, safari, chrome) act like mentioned above. So is there a way I can achieve the displaying the image in fancybox without spawning a new window/tab??
Many thanks...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,我没有时间完全重建您的情况,但可能是因为不是
target
,可能是因为 Google 地图脚本将click
事件绑定到一个
标签?在附加花式框之前尝试取消绑定所有事件:Excuse me, I have no time to full reconstruct your case, but may be cause is not a
target
, may be cause is Google Map script bindsclick
events toa
tag? Try to unbind all events before attach fancy box: