Search code examples
tabsreloadpageload

Load new URL in same tab after buttn click


I want to have a button on a page that links to a .pdf in a new tab (easy enough) but I also want that button to trigger the loading of a new url in the original tab. (So when the user closes the tab with the .pdf they see a new page has loaded in the original tab underneath.) Possible?


Solution

  • <a href="https://w3schools.com/" onclick="openNewTab()">
      <button type="button">Click me btn</button>
    </a>
    
    <script>
    function openNewTab() {
      window.open('https://google.com', '_blank').focus();
    }
    </script>