Search code examples
phpjavascriptcssphpbb3

scroll click event in js


I'm working with phpbb3 template now, and I want entire rows to be links to forums/topics. I tried making it without any scripts, but i feel it's too much messing up with the code.

Now I'm using

<tr onclick="window.location.href=http://example.com" />

but I want the link also open up in new tab on scroll click. Is there any method to attach window.open function to scroll click?


Solution

  • If you're using jQuery:

    $("tr").mousedown(function(e) {
        if(e.which == 2)
        {
            window.location = $(this).attr("onclick").replace('window.location.href=','');
        }
    } );
    

    Plain ol' javascript:

    document.onclick = function(e)
    {
        if(e.which == 2 && e.target.tagName == 'TR')
        {
            var loc = e.target.getAttribute('onclick').replace('window.location.href=','');
            window.location = loc;
        }
    }