I'm working on a web application in HTML/JavaScript, and I want to prevent users from calling functions in their browser console in order to avoid cheating. All these functions are contained in a unique file called functions.js
which is loaded in the head of the index.html
file.
After a search on the web I found this solution, which works fine in Google Chrome, but it is inefficient in other browsers such as Firefox:
var _z = console;
Object.defineProperty( window, "console", {
get : function(){if( _z._commandLineAPI ){ throw "Script execution not permitted" } return _z; },
set : function(val){ _z = val }
});
Is there a general way to disable functions call from console? Does it depend on the browser or is it just a problem of scoping or maybe something else that I have ignored?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…