Links from KML file opening new tab / browser window

530 views
Skip to first unread message

TomH

unread,
Apr 4, 2011, 7:56:13 AM4/4/11
to Google Maps JavaScript API v3
Hi

I am using a kml file to display polylines and markers with names and
descriptions.

If I include a link in the <description> and display in an info
window, it opens a new tab etc which I don't want. I thought the
solution would be to display the description in a div via innerHTML
but even when I do that, it still opens a window (yes I've tried
changing the target...)

Could anyone assist as I'm sure I've made a mistake. Otherwise it
seems odd that google should think that this needs to be a default
behaviour?

I've also tried to hijack the link by using js but google seems to
strip this out of the KML

Thanks.
TomH

Sample KML :
<description><![CDATA[
Test test test<br /><b>Date</b>: 19 March 2011<br /><a href='http://
example.com/show/1' target='_parent'>More Information</a>

]]>
</description>

Part of my js:
var kmlLayer = new google.maps.KmlLayer('http://www.example.com',
{suppressInfoWindows: true});
kmlLayer.setMap(map);

google.maps.event.addListener(kmlLayer, 'click', function(kmlEvent) {
var name = kmlEvent.featureData.name;
var descr = kmlEvent.featureData.description;
document.getElementById('Name').innerHTML = name;
document.getElementById('Description').innerHTML = descr;
});

TomH

unread,
Apr 4, 2011, 8:28:47 AM4/4/11
to Google Maps JavaScript API v3
Apologies but I've answered my own question. I replace this line

>   var descr = kmlEvent.featureData.description;

With this one
var descr = kmlEvent.featureData.description.replace(/ target="_blank"/
ig, "");

Michael Silverman

unread,
Aug 16, 2011, 11:27:12 PM8/16/11
to google-map...@googlegroups.com
Thanks Tom for posting the solution.  Wanted to do the same thing and luckily came upon you post.

Michael.

Nik Brockman

unread,
Dec 9, 2011, 5:30:02 PM12/9/11
to google-map...@googlegroups.com
Could you provide a link to your working example? I've been racking my brain for several days trying to get this to work and I'm convinced its impossible to override the target="_blank" on KML files.

Chad Killingsworth

unread,
Dec 10, 2011, 10:53:08 AM12/10/11
to google-map...@googlegroups.com
You can't override this, but you can implement your own info window handling and replace the attribute. Here's a snippet of code demonstrating the solution:

Reply all
Reply to author
Forward
0 new messages