0

I added an L.EasyButton to my map. Now I want it - by clicking - to open a new tab with a specific address.

I tried this but it did not work:

L.easyButton, function(btn, map){
    onclick="window.open('http://www.website.com/page')" 
}).addTo(map);

Any ideas?

1

Are you using a different language than JavaScript? Your code syntax seems weird.

You would simply do something like:

L.easyButton('fa-globe', function () {
    window.open("http://www.website.com/page");
}).addTo(map);

Demo: http://jsfiddle.net/ve2huzxw/45/

3
  • This still won't open a new tab in every case. To specify the target as a new tab, you have to provide _blank as a second argument to window.open. Like window.open("http://www.website.com/page", "_blank"); Nov 25 '15 at 13:32
  • Thank you for pointing out. Any example when it would not open a new window / tab? It seems it should be the default behaviour.
    – ghybs
    Nov 25 '15 at 13:44
  • Interestingly, I could not come up with a valid case, as _blank seems to be the default behaviour indeed. It seems like, I mixed it up with the anchor element's target property, for which _self is the default value. Nov 25 '15 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.