Formatting a variable as a link inside an infowindow on a map

OK, I can open a popup window and display my link (which is actually called an "address") However, I cannot make it display as a link inside an infowindow. I tried to put the address field to no avail. Obviously, the data falls into the info window, which I just can’t make a link to?

downloadUrl("http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx.php", function(data) { var xml = data.responseXML; var markers = xml.documentElement.getElementsByTagName("marker"); for (var i = 0; i < markers.length; i++) { var name = markers[i].getAttribute("name"); var address = markers[i].getAttribute("address"); var type = markers[i].getAttribute("type"); var point = new google.maps.LatLng( parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")) ); var html = "<b>" + name + "</b> <br/>" + "address"; xxxxxxxx var icon = customIcons[type] || {}; var marker = new google.maps.Marker({ map: map, position: point, icon: icon.icon, shadow: icon.shadow }); bindInfoWindow(marker, map, infoWindow, html); } } 
+4
source share
1 answer

If the address variable contains a link, then you can change the following line

 var html = "<b>" + name + "</b> <br/>" + "address"; 

to

 var html = "<strong><a href='" + address + "'>" + name + "</a></strong>"; 

which will do something like

 <strong><a href='http://someLink'>Some name</a></strong> 

So, clicking on Some name points to the link in the href property.

or I want you to do this

 var html = "<strong>" + name + "</strong> <a href='" + address + "'>address</a>"; 
+1
source

Source: https://habr.com/ru/post/1435612/


All Articles