---
title: viewer2d.contextmenu
slug: viewer-2d/events/contextmenu
docTags: 
createdAt: 2024-02-21T17:04:37.158Z
---

Invoked when the user performs a right click inside the viewer.

## Example

::codepen{url="https://codepen.io/Catenda/embed/MWMBgeJ"}

## Usage

:::CodeblockTabs
```javascript
const onContextMenu = function (event) {
  const { intersects } = event;
  console.log("viewer2d.contextmenu", "intersects:", intersects);
};

viewer2d.addEventListener("viewer2d.contextmenu", onContextMenu);
```

jQuery

```javascript
const onContextMenu = function (event, location, objectId) {
  console.log("viewer2d.contextmenu", "location:", location, "objectId:", objectId);
};

$("#viewer-2d").on("viewer2d.contextmenu", onContextMenu);
```
:::

## Parameters

### onContextMenu

::::Tabs
:::Tab{title="JS"}
Function called when the user performs a right click inside the viewer.

| **Type**                  |
| ------------------------- |
| `(event: Object) => Void` |

**event**

| **Name**         | **Type** | **Description**                               |
| ---------------- | -------- | --------------------------------------------- |
| `intersects`     | Object   | Object below the cursor, `undefined` if none  |
| `preventDefault` | Function | Disable space selection for right click event |
| `srcEvent`       | Object   | Original DOM event                            |

**intersects**

| **Name**   | **Type**                                | **Description**                         |
| ---------- | --------------------------------------- | --------------------------------------- |
| `objectId` | String                                  | Id of the object                        |
| `point`    | [Vector3](docId\:gQdK6kHl9IuzRieGxVDD0) | Intersection point of the object        |
| `normal`   | [Vector3](docId\:gQdK6kHl9IuzRieGxVDD0) | Normal vector at the intersection point |
:::

:::Tab{title="jQuery"}
Function called when the user performs a right click inside the viewer.

| **Type**                                                       |
| -------------------------------------------------------------- |
| `(event: Object, location: Object, objectId: String?) => Void` |

**event**

[jQuery.Event](https://api.jquery.com/category/events/event-object/)

**location**

Coordinates of the position clicked.

| **Name** | **Type** | **Description**                            |
| -------- | -------- | ------------------------------------------ |
| `x`      | Number   | X coordinate of pointer position in pixels |
| `y`      | Number   | Y coordinate of pointer position in pixels |
| `z`      | Number   | Height of the last storey shown in meters  |

**objectId**

Id of the object clicked, `undefined` if no object under cursor.
:::
::::

