Onleftclick & onrightClick javascript functions?

In my server-side code, I dynamically create a table, and now I am adding the following code to access a row click.

tr.Attributes.Add("onclick", "window.open('" + root + document.IPT_Name + "/" + document.IPT_Sub_Name + "/" + document.File_Name + "', 'mywindow', 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,copyhistory=no, resizable=yes')");

Is there a way to make this work only with a left click and then add another attribute to the right click to go to another location?

+3
source share
2 answers

You may find this, but there are some browser issues you should watch. Here is the code from http://www.quirksmode.org/js/events_properties.html

function doSomething(e) {
  var rightclick;
  if (!e) var e = window.event;
  if (e.which) rightclick = (e.which == 3);
  else if (e.button) rightclick = (e.button == 2);
  alert('Rightclick: ' + rightclick); // true or false
}

jQuery, : http://abeautifulsite.net/notebook/68

+3

, jQuery 1.3.2 , event.which event.button.

// Add which for click: 1 == left; 2 == middle; 3 == right
// Note: button is not normalized, so don't use it
if ( !event.which && event.button )
    event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
0

Source: https://habr.com/ru/post/1705728/


All Articles