JSFiddle - React, Tailwind, and code Playground

by vstuart

HTML

<html lang="en">
<!-- re: https://stackoverflow.com/q/76020358/1904943 -->
<head>

<script>
  function foo(obj) {
    globalThis.link = (obj.getAttribute("href"))
    console.log('[foo] link:', link);
    
    // -------------------------------------------
    //ISSUE HERE:
    // window = window.open("", "my_tab").focus();
    //
    // Solution, per:
    // https://stackoverflow.com/q/76020358/1904943
		//
		window = window.open("", "my_tab");
    my_window.focus()
     // -------------------------------------------

    my_window.location = "https://example.com/";
    setTimeout("bar(link)", 2000);
    return false;
    }

  function bar(link) {
    console.log('[bar] link:', globalThis.link);
    my_window.location=globalThis.link;
  }
</script>
</head>

<body>

<ul>
  <li><p><a target="my_tab" onclick="apple(this); return false;" href="https://dogpile.com/">Dogpile</a></p></li>

  <li><p><a target="my_tab" onclick="apple(this); return false;" href="https://duckduckgo.com/">DuckDuckGo</a></p></li>
</ul>

</body>
</html>