Georg Schölly
Georg Schölly

Reputation: 126085

How to make a javascript link behave like a html link?

I have to use Javascript for a link (at least I think so) in my openlayers map:

map.on("click", e => {
    map.forEachFeatureAtPixel(e.pixel, (feature) => {
        window.location.href = "/s/" + feature.getId();
        return true; // stop after first feature
    });
});

This works fine, but lacks some things:

I thought about listening to hover and checking if command is pressed, but this seems error prone and only works for known system configurations.

Is there a way to make a javascript link work just like a HTML link?

Upvotes: 0

Views: 77

Answers (1)

Adam Popkiewicz
Adam Popkiewicz

Reputation: 105

you can wrap your map with < a > tag and update href accordingly, that would:

  • give browser hint to propagate to user,
  • and could solve your separate tab/window issue.

you can also look at window.open, although it might be registered as 'popup' and blocked.

Upvotes: 1

Related Questions