1

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>'
});

1 Answer 1

5

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(){...}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.