开发者

calling javascript in infoWindow Google Maps

开发者 https://www.devze.com 2023-02-01 19:42 出处:网络
i am trying to call javascript inside the google maps infoWindow() but no luck. anyone know how to solved this issue? my coding as below:

i am trying to call javascript inside the google maps infoWindow() but no luck. anyone know how to solved this issue? my coding as below:

<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);
}
</sc开发者_如何学编程ript>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width: 640px; height: 480px; margin:1.5em 13.6em 1.5em 2em;">
</div>
</body>
</html>


fix this line

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

to this

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

精彩评论

暂无评论...
验证码 换一张
取 消