H
H
Haaaaz2022-03-14 13:02:19
JavaScript
Haaaaz, 2022-03-14 13:02:19

How to connect your JS script to a React project?

There is such a simple ContextMenuOff.js file that should simply disable the context menu on the site.

'use strict'

document.oncontextmenu = ev => {
    return false;
}


Question: how to connect it to a React project so that it works? I tried including it in index.html in body like this, but it doesn't work:
<body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <script src="./src/Scripts/ContextMenuOff.js"></script>
  </body>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2022-03-14
@haaaaz

<body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <script>
    document.oncontextmenu = ev => {
    return false;
    }
    </script>
  </body>

and the second option is to put your script in the public folder and change the path to it when connecting
to make it work, you need to stop and restart the react

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question