Hi,
The default Leaflet attribution add a link at the bottom-right of the map. If you click this link, it changes the current page and send the user to the leaflet webpage.
It is a bit annoying when you mis-click or when you touch it by accident because you lose the whole context (bounds) of your page. Setting the default link to target="_blank" should do the trick
Fabien
See: http://www.thatwebguyblog.com/post/dont_use_target_blank/
The target attribute has been deprecated for this reason. There are scripting workarounds, but it's considered a usability mistake to force new windows/tabs to open.
Hello Majiir,
I've never read that blogpost before and i find it quite narrow-minded. I know that if you middle click, you get any link in a new tab.
My use case is this. I'm using an iPad, panning around and i mis-touch the Leaflet link. It takes me to a new webpage and i've lost my work / context. Now this is a real usability issue. If the link wasn't right in front of the map, i would agree but you can easily click/tap it by accident.
Plus i don't even know if it is possible on an iPad to open link in a new tab voluntarily. I tried a long tap on it and nothing came up so i guess there is none.
I think it would benefit any leaflet user / dev.
Fabien
I am not familiar with Leaflet's behavior on the iPad. However, on my Android device, the attribution control is very small and difficult to accidentally tap. I suggest you try one (or both) of these ideas:
target attribute, which is deprecated in some HTML standards.ok, well, maybe the correction would to at least give the a element an id so that it can easily be fetched and modified
Fabien
This CSS selector (also usable with jQuery) should do the trick: .leaflet-control.attribution a
If you don't want to use jQuery, you can use getContainer() on the attribution control object and find the anchor tags from there.
@fnicollet you can change the prefix on the fly like this:
map.attributionControl.setPrefix('your new powered by prefix with target=blank');
I'll close this for now as I agree the best practice is not to force opening new windows (unless you're embedding it in an iframe).
Most helpful comment
@fnicollet you can change the prefix on the fly like this:
I'll close this for now as I agree the best practice is not to force opening new windows (unless you're embedding it in an iframe).