• igby

    (@igby)


    Hi, I have some code in my site that makes it so that clicking on an image redirects to a new site. I want to add to that code so that the link opens in a new tab. Here is the code I’m using:

    <script>
    document.getElementById(‘poster’).onclick = function() {location.assign(‘link.com’);
    };
    </script>

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try:

    document.getElementById('poster').onclick = function() {
    window.open('https://example.com', '_blank');
    };
    Thread Starter igby

    (@igby)

    Hmm … it seems to need the
    {location.assign

    in order to open the link.

    Would I be able to add

    {window.open

    before/after the location assignment part?

    Thank you for your help!

    • This reply was modified 5 years ago by igby.
    • This reply was modified 5 years ago by igby.
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘HTML redirect in new tab’ is closed to new replies.