Page 5 of 5

Create new infoWindow for multiple markers generated from REST.

Posted: Thu Mar 19, 2015 6:43 am
by EJLD

Hi There, how you guys doing ?

when clicking on a googlemap marker, there is an infowindow popingup. that works well.
i wanted to insert a button in this infowindow.setContent.
the button appears well.
however, the function is not triggered. error msg is "invite4Game is not defined"

here after is my code, would you guys point out something wrong ?
thk you very much in advance

<!--
// call infowindows on click
google.maps.event.addListener(marker, 'click', (function(marker, j) {
...
infowindow.setContent('<div'+locations[j][0]+'<br<img src='+IdPicSrc+' style="width:100px;height:100px"<button onclick="invite4Game()"invite4Game</button<');
// infowindow position above the chosen marker
infowindow.open(map, marker);
},2500); // end of a setTimeout
};
})(marker, j));

Code: Select all

 var collector = locations[j][0]; 

 function invite4Game() { 
    some code ... ; 
 } 

} // end of listener function

--


Create new infoWindow for multiple markers generated from REST.

Posted: Sat Mar 21, 2015 3:01 pm
by Egor Kotov6832188

Hello EJLD,

invite4Game function is initialized in different scope for your onclick event, cause your google.maps.event.addListener added to the page as a separate global function in it's own context.

Solution: place invite4Game in same scope


Create new infoWindow for multiple markers generated from REST.

Posted: Sat Mar 21, 2015 10:57 pm
by EJLD

Hi Egor, thk you. I'll check this.