How to change Google logo's href

2019-09-12 00:32发布

问题:

I would like to change the “Click to see this area on Google Maps” link, but I can't select the proper a tag.

Thanks

回答1:

You can take advantage of RobH's answer

var anchors = document.getElementsByTagName('a'),
    l = anchors.length,
    i,
    a;

for (i = 0; i < l; i++) {
    a = anchors[i];
    if (a.href.indexOf('maps.google.com/maps?') !== -1) {
         // here you can manipulate the anchor
         a.title = ''; 
         a.onclick = function () { return false; };
    }
}

NOTE

Remember It's against the Google Maps API ToS to remove the Google branding or the ToS link.



回答2:

I noted that changing the href is not desirable because every time the map is dragged or zoomed in/out, the href is set to a new value. So setting an event, as suggested in davcs86's answer, is the best approach.

Here is the code:

$(document).on("mousedown", "a[href$='mapclient=apiv3']", function(){
  $(this).attr("href", "http://NEW-URL-YOU-WANT");
});

I used onmousedown instead of onclick because it responds to the middle button.