Frequently asked question

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

Last Published: April 25, 2020

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

Article ID: 000014590

Software:
  • ArcGIS API for JavaScript 4 x
  • ArcGIS API for JavaScript 3 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options