3

In my server side code I am dynamically building a table and and right now I am adding the following code to handle the 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 any way to make this work only a left click and then add a different attribute to the right click to go to a different location?

2 Answers 2

3

You can detect it, but there are some browser specific issues you have to watch. Here is some 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
}

There's also a plug-in for jQuery that lets you detect right mouse clicks: http://abeautifulsite.net/notebook/68

Sign up to request clarification or add additional context in comments.

Comments

0

Here's some code taken out of jQuery 1.3.2 with comments that explain about event.which and 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 ) ));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.