可以从浏览器检查器控制台禁用Javascript / Jquery吗? [英] Is possible to disable Javascript/Jquery from the browser inspector console?

查看:146
本文介绍了可以从浏览器检查器控制台禁用Javascript / Jquery吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在考虑是否有任何方法可以禁用从检查器控制台更改javascript / jquery的功能?

Hi i was thinking about if there could be any way of disable the ability to change the javascript/jquery from the inspector console?

以防万一你想要避免用户使用控制台从DOM交互和更改内容,或者发送表单以避免从javascript进行一些检查。

Just in case you want to avoid that a user interacts and change things from the DOM using the console, or maybe send forms avoiding some checks from javascript.

或者不可能这样做而你只是拥有在服务器端做所有安全或这类事情?

Or is impossible to do that and you just have to do all the security or this kind of things on the serverside?

谢谢!

推荐答案

是,禁用控制台只需在客户端上运行

Yes to disable the console just run this on the client

Object.defineProperty(console, '_commandLineAPI', {
    get : function() {
        throw "Console is disabled";
    }
});

这不会让我们使用控制台。

This won't leave then to use the console.

注意:没有100%安全的选项来解决这个问题,但至少这样做不会允许控制台使用。为您的服务器添加安全性以查看哪些请求是合法的。

Note: There isn't a 100% secure option to get around this, but at least doing this won't allow console usage. Add security to your server to see which request are legit.

此外,这仅适用于Chrome,这是因为Chrome将所有控制台代码包装在:

Also this will only work in Chrome this is because Chrome wraps all the console code in:

with ((console && console._commandLineAPI) || {}) {
  <code area>
 }

Firefox有一种不同的方式来从控制台包装代码。这就是为什么这不是对控制台命令的100%安全保护

Firefox has a different way to wrap the code from the console. This is why this is not a 100% secure protection from console commands

这篇关于可以从浏览器检查器控制台禁用Javascript / Jquery吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆