Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent html/JavaScript code modification

I would like to know if there is a way to prevent an html page with jQuery or javascript to be modified by the user to change its behavior.

A user can modify it using tools such as FireBug or the Google Chrome developer bar to hide or show divs, add event listeners to page elements and so on.

I've seen some web pages showing a blocking div when the page is loaded and a pop-up telling to answer some question. If you answer it, the div hides and you can see the page normally. But if you try to hide the blocking div using FireBug, the page reloads and there is no way to see the page correctly if you don't ansewer the question asked in the pop-up.

I want to know how could I prevent user from doing such things.

Thanks a lot.

like image 956
Maik Avatar asked Nov 07 '10 18:11

Maik


People also ask

How do I block JavaScript in HTML?

Open Chrome DevTools. Press Control+Shift+P or Command+Shift+P (Mac) to open the Command Menu. Start typing javascript , select Disable JavaScript, and then press Enter to run the command. JavaScript is now disabled.

Can browser modify JavaScript?

Editing JavaScript code in real-time is possible in Chrome and Chromium based browsers. After loading a web page completely, press the F12 key to open the developer tools, then open the 'Sources' tab. Now open any Javascript file loaded on the browser and you can directly edit it by clicking anywhere in that file.


2 Answers

It is not possible (which is a very good thing).

like image 85
jAndy Avatar answered Sep 21 '22 21:09

jAndy


To defeat the method described in the question:

  • You can use the keyboard shortcuts to the console/tools (Ctrl+Shift+I in Chrome)
  • You can use the resource/net panel to see the source
  • You can see it at any other level, e.g. Fiddler
  • You can use a bookmarklet for easier access

No, you can't prevent people seeing or modifying your source/script if they want to...the ones you most want to prevent are the most able to circumvent any deterrent (and that's all anything you do is, a deterrent, not a stop) you put in place.

like image 20
Nick Craver Avatar answered Sep 23 '22 21:09

Nick Craver