[GIS] Displaying link in popup with Leaflet

leafletpopup

I'm working with the Leaflet JavaScript library. There should be an option to click on my map and view a popup. I already have a code for that:

var popup = L.popup();

function onMapClick(e) {
popup
    .setLatLng(e.latlng)
    .setContent(e.latlng.toString() + "<br><b>Visit Google</b>")
    .openOn(map);
}

map.on('click', onMapClick);

This code is working, but my question is: how can i put an link to that popup? For example there should be a link called "Visit Google". When you click on that link it should open www.google.com (surprise). I think it should be in the .setContent(e.latlng.toString()) tag, because I can add there a text like Visit Google (as you can see).

Any ideas ?

Best Answer

You are providing html in setContent()

var popup = L.popup();

function onMapClick(e) {
popup
    .setLatLng(e.latlng)
    .setContent(e.latlng.toString() + '<a href="http://www.google.com">Visit Google</a>"')
    .openOn(map);
}

map.on('click', onMapClick);