在InfoWindow中调用JavaScript函数(Google Maps) [英] Calling a JavaScript function within an InfoWindow (Google Maps)

查看:122
本文介绍了在InfoWindow中调用JavaScript函数(Google Maps)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google地图InfoWindow中遇到了调用javascript函数的问题。相关代码如下:

I'm having an issue calling a javascript function within a Google Maps InfoWindow. The relevant code is below:

<script type="text/javascript">
<!--
/* … unnecessary code */

function closeTo(url_slug) {
    parent.url_slug = url_slug;
    parent.$.fancybox.close();
}

var contentString = '<a href="javascript:closeTo(\'foo\');">close</a>';

var callout = new google.maps.InfoWindow({
    content:contentString
});

//-->
</script>

上面的例子产生一个空白的地图。但是,如果我将内容字符串更改为:

The above example results in a blank map. However, if I change the content string to this:

var contentString = '<a href="#">close</a>';

它工作得很好。此外,我从页面上的链接(而不是InfoWindow)调用函数,它也可以工作。总体思路是响应InfoWindow中的点击,关闭fancybox并重定向到提供的位置。所以,我的问题是这样的。如何在InfoWindow中调用函数?

It works just fine. Also, I've called the function from a link on the page (not an InfoWindow) and it works as well. The general idea is to respond to a click in an InfoWindow, close the fancybox, and redirect to the location provided. So, my question is this. How do I call a function within an InfoWindow?

推荐答案

没有任何内在错误,从infoWindow中调用一个javascript函数。我建议你检查JavaScript错误日志,并尝试跟踪调用 closeTo 后发生的事情。

There is nothing inherently wrong with calling a javascript function from an infoWindow. I suggest you check the JavaScript error log and try and track down what is happening once closeTo is called.

这篇关于在InfoWindow中调用JavaScript函数(Google Maps)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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