How to override target = _blank in KML pop-ups in the embedded Google map?

I use KML to overlay shapes on a Google map. Information corresponding to each form is included in the element <description>, as well as a link to the details page corresponding to this form.

So, for example, my KML includes the following:

<description>
    <![CDATA[
    <div>

     ...

        <p>
            <a href="Concession.20.aspx">View details</a>
        </p>
        &nbsp;
    </div>
]]>

Of course, I would like this link to open in the same window, because it just went to another page on the same site. Unfortunately, as described here , links embedded in <description>a KML file element are rewritten with target='_blank'.

Targets are ignored when included in HTML written directly in KML; all such links open as if target is set to _blank. Any specified goals are ignored.

: - , ( , ) ?

click ( jQuery), Google, .

+5
6

, jQuery infowindowopen. :

    map = new google.maps.Map2(document.getElementById("map"));

    ...

    GEvent.addListener(map, "infowindowopen", function() {
        // Get a reference to the infoWindow
        var infoWindow = $(this.getInfoWindow().getContentContainers());
        // Find all <a> tags in the infoWindow and reset their target attribute
        $("a", infoWindow).attr("target", "_self");
    });
+3

. jQuery, .

  $('#map_canvas').delegate('a', 'click', function(event) {
    window.location.href=$(this).attr('href');
    return false;
  });
+6

.

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
function initialize() {
  var myLatlng = new google.maps.LatLng(49.8,15.8);
  var myOptions = {
    zoom: 7,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControl: false
  }
  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

  var ctaLayer = new google.maps.KmlLayer('http://zonglovani.info/mapa/mapa-cz.kml');
  ctaLayer.setMap(map);

  google.maps.event.addListener(ctaLayer, 'click', function(kmlEvent) {
    kmlEvent.featureData.description = kmlEvent.featureData.description.replace(/ target="_blank"/ig, "");
  });
}

function loadScript() {
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initialize";
  document.body.appendChild(script);
});

window.onload = loadScript;
</script>
+2

, jQuery: ( , Google Map div "iw", "iw_kml" )

$('#iw a').live('click', function () {
   $(this)... (Gives you the clicked a-object)

});

.

+1

Google Map API V3, - . , , , :

google.maps.event.addListener(mapKmlLayer, 'click', function(kmlEvent) {
  kmlEvent.featureData.description = kmlEvent.featureData.description.gsub("_blank", "_self");
}); 
+1

, onclick :

onclick='return false;'

target = "_ self" .

but if you want to switch to another target or remove pheraps, you have to add a listener and javascript replacement as follows:

  GEvent.addListener(map,"infowindowprepareopen", function(iwtabs) {
  iwtabs[0].contentElem.innerHTML = iwtabs[0].contentElem.innerHTML.replace("_blank", "_parent");
  });

this is very useful when you have a lightbox (or similar) link inside the infowindow window.

amuses

0
source

All Articles