Google Maps API - 无法点击信息窗口中的链接
我在 Javascript 中的 GoogleMaps API v3 中遇到 InfoWindow 问题。我已经成功创建了一个信息窗口,我可以在里面设置任何内容,但我想在里面放一个超文本链接。它工作正常,我通常将标记放入 setContent() 方法,并且链接正确显示在窗口中。不幸的是,它不可点击 - 它附有一个正确的链接,但当我点击它时,什么也没有发生。当我通过右键单击它并选择“在新窗口中打开”时,它工作得很好。有人能找出这里的问题吗?我有一个简单的代码,如下所示:
var bubble;
... some lines not related to the bubble ...
bubble = new google.maps.InfoWindow({
maxSize: new google.maps.Size(500,250)
});
... other not related lines...
然后我在创建标记的事件中触发它(对于标记来说效果很好):
bubble.setContent('<a href="http://www.google.com">LINK</a>');
google.maps.event.addListener(marker, 'click', function() {
bubble.open(map, marker)
});
其中“地图”和“标记”都很好。
I've got a problem with InfoWindow in GoogleMaps API v3 in Javascript. I have successfully created an info window, I can set any content inside, but I want to put a hypertext link inside. It works fine, i put normally tag to the setContent() method and the link appears in the window correctly. Unfortunately, it is NOT clickable - it has a correct link attached to it, but when I click on it, nothing happens. When I click on it by right button and select "Open in new windows", it works just fine. Can anyone find out a problem here? I've got a code as simple as follows:
var bubble;
... some lines not related to the bubble ...
bubble = new google.maps.InfoWindow({
maxSize: new google.maps.Size(500,250)
});
... other not related lines...
then I trigger it in an event that creates markers (works fine for the markers):
bubble.setContent('<a href="http://www.google.com">LINK</a>');
google.maps.event.addListener(marker, 'click', function() {
bubble.open(map, marker)
});
where both "map" and "marker" are just fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题。我相信这是因为 infowindow 内容作为 div 动态插入到 DOM 中而引起的。我不知道为什么会发生这种情况,但这是我解决它的方法:
添加 jQuery 处理程序以捕获链接并关注它
$(".infowindow_link").live('click', function(){
window.location.href=this.href;
});
这个“实时”调用跟踪 DOM 的更改,并将侦听器附加到您插入的任何新链接。 window.location.href 更新是跟踪链接的正常行为。
I faced the same problem. I believe this is being caused because the infowindow content is dynamically inserted into the DOM as a div. I don't know why this exactly happens, but here is how I solved it:
Add a jQuery handler to capture the link and follow it
$(".infowindow_link").live('click', function(){
window.location.href=this.href;
});
This 'live' call tracks changes to the DOM and attaches the listeners to any new links you insert. The window.location.href update is the normal behavior of following a link.