Use the mousedown event type instead of click:

yourThing.addEventListener("mousedown", clickThing);

Check the MouseEvent buttons property:

function clickThing(event) {
    if (event.buttons == 1) { // check if the left mouse button is pressed
        // your left click code here
    else if (event.buttons == 2) { // check if the right mouse button is pressed
        // your right click code here

Disable the context menu with the contextmenu event type:

yourThing.addEventListener("contextmenu", disableContextMenu);

function disableContextMenu(event) {
    // the default browser action is to show the context menu
    // this prevents the default browser action from happening