Table Row onclick - change page, or open new tab

12,519

This works for me:

<tr onclick="window.open('http://www.google.com','_blank')">
Share:
12,519
Programster
Author by

Programster

Updated on June 14, 2022

Comments

  • Programster
    Programster almost 2 years

    I have a table with rows, that when clicked, take the user to a page with more detailed information about the item that row was describing. Unfortunately, it always changes the current page, and our users would like to be able to middle-mouse/control click the rows in order to open a new tab if they want to. This choice is available with normal links, but not with my onclick it seems. An example is shown below:

    <html>
        <body>
            <table border='1'>
            <tr onclick='window.open("http://www.google.com")'>
                <td>Open Another Window</td>
            </tr>
            <tr onclick='location.href="http://www.google.com"'>
                <td>Change Current Page</td>
            </tr>
            </table>
        </body>
    </html>
    

    What is the best way to simulate a normal link with an onclick event so the behaviour will be the same across different os/browsers, which I believe have different bindings for what triggers opening a link in a new tab.