English

FAQ: Is it possible to disable the right-click function in a web app configured in ArcGIS API for JavaScript for security purposes?

Question

Is it possible to disable the right-click function in a web app configured in ArcGIS API for JavaScript for security purposes?

Answer

Yes, it is possible to disable the ability to right-click a web app configured using ArcGIS API for JavaScript. Administrators and developers may want to disable right-clicking, for example, to prevent users from viewing the back-end source code when viewing web maps in a supported web browser. This raises security concerns, as sensitive data may be involved in the creation of the web map (such as picture files.)

The example screenshot below is taken from Google Chrome. In general, users can right-click anywhere on the page and select View page source.

The picture of right-click > view page source

To counter the problem, a code snippet can be added to the <body> part of the JavaScript file, as follows:

...
<body oncontextmenu="return false">
...
Note:
Upon adding the above code snippet, any context menu created to allow edits is now unavailable.

Related Information