javascript 在 Inspect Element Editor 中更改 JS 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31277707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change JS code in Inspect Element Editor
提问by Vivek Sadh
When I make some changes in html content using Chrome's Inspect Element editor the changes are immediately reflected. But when I make a change in Javascript code then the changes are not reflected.
当我使用 Chrome 的 Inspect Element 编辑器对 html 内容进行一些更改时,这些更改会立即反映出来。但是当我对 Javascript 代码进行更改时,这些更改不会反映出来。
Suppose on click of a button I say, alert "John is a Good boy" and When I change it to "John is a bad boy" using Inspect element(JS code) then the changes are not reflected on button click and the old text "John is a Good boy" gets displayed.
假设单击按钮时我说,提醒“约翰是一个好男孩”,当我使用 Inspect 元素(JS 代码)将其更改为“约翰是一个坏男孩”时,更改不会反映在按钮单击和旧文本上显示“约翰是个好孩子”。
So when a page gets loaded, its not possible to edit the JS code and see the changes ? Why is it so ?
因此,当页面加载时,无法编辑 JS 代码并查看更改?为什么会这样?
回答by Jake Magill
In my experience, the edits I've made to Javascript files have been reflected immediately. However, an easy fix you might try is as follows:
根据我的经验,我对 Javascript 文件所做的编辑会立即反映出来。但是,您可以尝试一个简单的修复方法如下:
- Insert a breakpoint on the line you want to edit
- Reload the page (breakpoints will persist)
- Edit that line when the breakpoint is hit
- Click Continue on the debugger
- 在要编辑的行上插入断点
- 重新加载页面(断点将持续存在)
- 当断点被击中时编辑该行
- 单击调试器上的继续
If you need more information on breakpoints and the debugger, check out this link
如果您需要有关断点和调试器的更多信息,请查看此链接
If you want even more information on using the inspector tool, try searching through this tutorial
如果您想了解有关使用检查器工具的更多信息,请尝试搜索本教程
回答by A. Figueroa
Altering the JavaScript of a page through the browser is considered a malicious practice. Imagine that someone removes all the logic from you login method and then has it return true;
.
通过浏览器更改页面的 JavaScript 被视为恶意行为。想象一下,有人从您的登录方法中删除了所有逻辑,然后拥有它return true;
。
Malicious users could exploit your system by making targeted changes to your system. So browsers prevent you from making those changes live.
恶意用户可以通过对您的系统进行有针对性的更改来利用您的系统。因此浏览器会阻止您进行这些更改。
If you really wanted to, I guess you could download all the source files, make your changes and then have a browser load the project. The project should preserve your changes. Although, the webmaster probably has mechanism in place to prevent any incoming requests to his server from Cross Origin (XSS). Recognizing that the edited requests are not coming from the correct origin, the server should reject and potentially try to log/track the malicious attempt.
如果您真的想要,我想您可以下载所有源文件,进行更改,然后让浏览器加载项目。该项目应保留您的更改。尽管如此,网站管理员可能已经制定了机制来防止来自跨域 (XSS) 的任何传入请求到他的服务器。认识到编辑的请求不是来自正确的来源,服务器应该拒绝并可能尝试记录/跟踪恶意尝试。