2013-11-15 50 views
2

我使用這個代碼我如何能在谷歌地圖上禁用右鍵點擊信息窗口

function initialize() { 
    var myLatlng = new google.maps.LatLng(-25.363882,131.044922); 
    var mapOptions = { 
    zoom: 4, 
    center: myLatlng, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 

創建信息窗口加載地圖在我的web應用程序:在方含格

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

    var marker = new google.maps.Marker({ 
     position: myLatlng, 
     map: map, 
     title: 'My Title' 
    }); 
    google.maps.event.addListener(marker, 'click', function() { 
    infowindow.open(map,marker); 
    }); 
} 

我已禁用右鍵點擊

$(document).bind("contextmenu",function(e){ 
       e.preventDefault(); 
      }); 

但仍然右鍵點擊infowindow默認的上下文菜單是appering。

我的問題是我如何禁用右鍵單擊infowindow?

回答

2

您需要爲infoWindow的content而不是字符串傳遞DOM元素。然後你可以在你的元素上設置事件。

這裏是JSFiddle example