GMaps V3 InfoWindow - disable the close “x” button

前端 未结 22 936
青春惊慌失措
青春惊慌失措 2020-12-05 09:14

From what I see, in v2 of GMaps API there was a property \"buttons\" of the InfoWindow object that one could define in a way that given InfoWindow has no close button:

相关标签:
22条回答
  • 2020-12-05 10:01

    This works

    .gm-style-iw > button {display: none !important;}
    
    0 讨论(0)
  • 2020-12-05 10:02

    You can also do it through the css.

    .gm-style-iw + div {display: none;}
    

    edit january 2019
    as @antmeehan said in the comment,

    Google have changed the HTML, and the close button is now a button element rather than a div

    So the css code to hide the "x" button is now:

    .gm-style-iw + button {display: none;}
    
    0 讨论(0)
  • 2020-12-05 10:02

    if using jquery just add this

    $(".gm-style-iw").next("div").hide();
    
    0 讨论(0)
  • 2020-12-05 10:03

    Thanks Tushar, but also you need put this code in event handler

    google.maps.event.addListener(infowindow, 'domready', function(){
        $(".gm-style-iw").next("div").hide();
    });
        

    0 讨论(0)
  • 2020-12-05 10:04

    To extend on Louis Moore's answer, you can also center the text after removing the close button:

    .gm-style-iw + div {display: none;}
    .gm-style-iw {text-align:center;}
    

    Without Centering:

    With Centering:

    0 讨论(0)
  • 2020-12-05 10:04

    I used the answer given by Tushar Gaurav, but expanded it a little...

    $(".gm-style-iw:contains(" + infoText + ")").css("left", function() {
        return ($(this).parent().width() - $(this).width()) / 2;
    }).next("div").remove();
    

    That will remove the X from an infowindow with the text in infoText, and then recenter the text as it's off-center after removing the close button.

    Just adding this for anyone else who stumbles across this page as I did.

    0 讨论(0)
提交回复
热议问题