Inside the google maps infowindow object I have called the showHotel() function but it did not gets called. When I just write alerert('') is works but my own defined function did not work.
function showHotel() {
alert('Wapal po');
}
var infowindow = new google.maps.InfoWindow({
content: '<a href="#" onclick="showHotel()">Show Tasweer</a>'
});
dumbass
27.2k4 gold badges43 silver badges77 bronze badges
asked Nov 12, 2011 at 10:52
Shahid Karimi
4,42317 gold badges67 silver badges108 bronze badges
1 Answer 1
You should globally declare showHotel. If you add event listeners to a HTML string, the current scope is not respected. Your current code probably looks like:
window.onload = function(){ //Or any inner function
function showHotel() ... //This declares a local method
...
content: '<a ... onclick="showHotel()">'
...
}
A method to leak the showHotel method to the global scope is by prefixing the method by window.:
window.showHotel = function(){...}
answered Nov 12, 2011 at 11:00
Rob W
351k87 gold badges811 silver badges683 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js