Links with target=_blank opens in browser

Viewed 637

In my PWA website, I have in a few places, links that open in new tab using target="_blank". I want to maintain this functionality but not if the user has installed the PWA.

Currently, if the user installs the PWA and click on that link, the user is taken to the browser and the page loads there.

I have tried all different kinds of scope but all give same result.

/
./
https://beta.domain.com/
1 Answers
// Add this script after </body>
<script>
if (window.matchMedia('(display-mode: standalone)').matches) { 
  // if webapp installed, remove 'target' attribute of links
  document.querySelectorAll('a[target=_blank]').forEach(function(a) {
     a.removeAttribute('target');
  });
}
</script>
Related