disable-context-menu

1.0.1 • Public • Published

Disable Context Menu

This package is used to disable context menu / inspect element / right click in your web applications.

Usage

  1. First import the package in your application's root.
import { disableContextMenu } from 'disable-context-menu';
  1. Now call disableContextMenu in your applications. e.x
if (process.env.NODE_ENV === 'production') {
  disableContextMenu();
}

This can be used in react / vue / ember / venilla js applications.

Examples

  1. React index.js (main entry of your react application) you can use like this
import React from 'react';
import ReactDOM from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import { disableContextMenu } from 'disable-context-menu';
import App from './components/App';

const root = ReactDOM.createRoot(document.getElementById('react-app'));

if (process.env.NODE_ENV !== 'development') {
  disableContextMenu();
}

root.render(
  <BrowserRouter>
    <App />
  </BrowserRouter>
);
  1. Vue app.js (In your vue applications you can call this function in your root entrypoint file)
import { createApp } from 'vue'
import { disableContextMenu } from 'disable-context-menu';

if (process.env.NODE_ENV !== 'development') {
  disableContextMenu();
}

const app = createApp({
  el: '#app'
})
  1. Angular app.component.ts (main bootstrap component in your application)
import { Component, OnInit } from '@angular/core';
import { disableContextMenu } from 'disable-context-menu';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class App implements OnInit {
  constructor() {}
  
  ngOnInit() {
    disableContextMenu();
  }
}

Package Sidebar

Install

npm i disable-context-menu

Weekly Downloads

11

Version

1.0.1

License

ISC

Unpacked Size

2.82 kB

Total Files

3

Last publish

Collaborators

  • shahidullahkhan