'Change JS code in Inspect Element Editor
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.
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.
So when a page gets loaded, its not possible to edit the JS code and see the changes ? Why is it so ?
Solution 1:[1]
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:
- 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
Solution 2:[2]
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;
.
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.
Solution 3:[3]
If you want to change something that is inside a function, then you can do that by pressing control + s (on windows). that works for most games at least, like a version of Tetris that I wanted to have some fun in. I found this in the first link that @jake magill provided.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jake Magill |
Solution 2 | A. Figueroa |
Solution 3 | smooshymemes |