Open Popup based on target attribute

HTML

<html>

<body>
<a href="https://phpwcms.org" target="popup">Popup 1 öffnen</a>
<a href="https://forum.phpwcms.org" target="popup">Popup 2 öffnen</a>

<script>
document.addEventListener("DOMContentLoaded", (event) => {
  let popupLinks = document.body.querySelectorAll('a[target="popup"]');
  for (let i = 0; i < popupLinks.length; i++) {
    let link = popupLinks[i].href;
    if (link) {
      popupLinks[i].addEventListener('click', function(event) {
          event.preventDefault();
          // https://developer.mozilla.org/en-US/docs/Web/API/Window/open
          window.open(link, 'mypopup', 'popup=true,width=500,height=800');
      });
    }
  }
});
</script>
</body>
</html>