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, the oncontextmenu property must be added and set to return false to the <body> tag of the JavaScript file as follows:

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

The following image is an example of how the <body> tag looks in a script.

The image of the JavaScript code segment

Related Information