在infoWindow谷歌地图中调用javascript

时间:2010-12-29 04:13:38

标签: google-maps

我试图在谷歌地图infoWindow()内调用javascript但没有运气。有谁知道如何解决这个问题?我的编码如下:

<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
    html { height: 100% }
    body { height: 100%; margin: 0px; padding: 0px }
    #map_canvas { height: 100% }
</style>
<script type="text/javascript"src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
    function initialize() {
    var image = 'image.png';
    var myOptions = {
        zoom: 15,
        center: new google.maps.LatLng(3.101669,101.635793),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    var myHtml = "<script type='text/javascript'>alert('test');<\/script>";
    var infowindow = new google.maps.InfoWindow({content: myHtml});
    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(3.09667,101.635793),
        map: map,
        title:"Hey, I'm here!",
        <!--icon: image-->});
    google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map,marker);});
    infowindow.open(map,marker);
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width: 640px; height: 480px; margin:1.5em 13.6em 1.5em 2em;">
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

修正此行

var myHtml = "<script type='text/javascript'>alert('test');<\/script>";

到这个

var myHtml = "<scr"+"ipt type='text/javascript'>alert('test');</scr"+"ipt>";