Question

Attempting to use a leaflet map for the first time ...

Wondering how to add a link to a leaflet's pop-up window?

I've tried doing something like this:

 var marker = L.marker([34.063298, -118.280126]) .addTo(map).bindPopup("<b>Blah blah Village</b><a href="http://www.cnn.com">Test</a>").openPopup();

Clearly, it doesn't work.

How do I add a simple link? Or even an image?

Thanks.

Was it helpful?

Solution

Your problem is quotes.

"<b>Blah blah Village</b><a href="http://www.cnn.com">Test</a>"

This is a string

"<b>Blah blah Village</b><a href="

And then some text, and then the string

">Test</a>"

To fix the issue, you would use different quotes for inner versus outer.

"<b>Blah blah Village</b><a href='http://www.cnn.com'>Test</a>"

Using your debug extensions would help you track this issue down faster.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top