如何在kml弹出窗口中覆盖target =“_ blank”

时间:2012-07-19 14:15:38

标签: google-maps google-maps-api-3 kml

我正在谷歌的地图中使用如下代码加载kml:

var myOptions = {
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
var kmlLayer = new google.maps.KmlLayer('https://maps.google.com/maps/ms?authuser=0&vps=2&ie=UTF8&msa=0&output=kml&msid=209879288832578501414.0004c52d678cf88f70685');
kmlLayer.setMap(map);

问题是指向弹出窗口kml adds target="_blank"的链接,我不想要它。

如何使用javascript删除它?我发现this answer但它在API 3中不起作用。我不喜欢使用jQuery。

2 个答案:

答案 0 :(得分:0)

通过jQuery,

加载地图后执行此操作

$('a[target="_blank"]').prop('target','_self'); 

答案 1 :(得分:0)

根据@geocodezip的评论,我得到了一个解决方案。它并不完美,InfoWindow从标记的底部而不是头部开始,但是它是一些东西。

var infoWindow;
var map;

function initialize() {
    var myOptions = {
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);

    var opts = {suppressInfoWindows: true};
    var kmlLayer = new google.maps.KmlLayer('https://maps.google.com/maps/ms?authuser=0&vps=2&ie=UTF8&msa=0&output=kml&msid=209879288832578501414.0004c52d678cf88f70685', opts);
    kmlLayer.setMap(map);

    infoWindow = new google.maps.InfoWindow();

    google.maps.event.addListener(kmlLayer, 'click', function(kmlMouseEvent) {
        var name = kmlMouseEvent.featureData.name;
        var descr = kmlMouseEvent.featureData.description.replace(/ target="_blank"/ig, '');
        var dom = '<div style="font-family: Arial, sans-serif; font-size: small">' +
            '<div style="font-weight: bold; font-size: medium; margin-bottom: 0em">' +
            name +
            '</div>' +
            '<div>' +
            descr +
            '</div>' +
            '</div>';
        infoWindow.setContent(dom);
        infoWindow.setPosition(kmlMouseEvent.latLng);
        infoWindow.open(map);
    });
}