Home  >  Q&A  >  body text

Userscript How to prevent the execution of a certain function in inline js?

// ==/UserScript==

(function() {
    bad = {};
})();

Can be disabled:

<html>
    <body>
        <a onclick="bad();">Click</a>
        <script> 
            bad = function() {alert("bad");}
        </script>
    </body>
</html>

Cannot be disabled:

<html>
    <body>
        <script> 
            bad = function() {alert("bad");}
            bad();
        </script>
    </body>
</html>

How to block the second situation

给我你的怀抱给我你的怀抱2663 days ago770

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-07-05 10:59:02

    const bad = {};
    

    This way your function cannot be reassigned. But when assigning a value, an error occurs.

    Or try using Proxy.

    reply
    0
  • Cancelreply