-2

How to hide my HTML CSS JS source code and show some random characters when someone view the source by clicking the right button of mouse. I have given a link where the code is hidden and some characters have been shown. I have also attached an image for better understanding.

view-source:https://devitems.com/html/reflex-preview/reflex/index-3.html

enter image description here

Mike
  • 23,542
  • 14
  • 76
  • 87
Zaman
  • 117
  • 1
  • 2
  • 10
  • There is no way to hide html code. You can decode the image you posted above. Also there is no need to hide html, js, css or anything else. – Manuel Mannhardt Oct 20 '16 at 19:37
  • 2
    Long story short, as long as you want to the user to be able to run the code the user will be able to read the code. Maybe consider why you want to hide the source – JimL Oct 20 '16 at 19:40
  • 1
    http://imgur.com/a/AxqpM — Nothing is protected and it took an ungodly amount of time and CPU to render the page. Don't waste everyone's time with such stupid tricks. – Quentin Oct 20 '16 at 19:44
  • 2
    it's always funny when people try to hide stuff, remember when people would disable right click especially for photos. – Rob Allen Oct 20 '16 at 19:47

2 Answers2

0
  1. You can first encode all your script content using encodeURI native browser function.

  2. Inject to the page as plain text or local variable value

  3. Then decode using decodeURI function

  4. inject result into the page using document.write(decodedContent)

VadimB
  • 5,533
  • 2
  • 34
  • 48
0

As I mentioned in my comment, there is simply no way to hide html, css or javascript. The example you have shown above it not hiding or encrypting anything. All you have to do, to get the 'real' html markup, is using for example PHP's urldecode function. Also, there is no reason to do so. If you have something, that no one should see, dont put it on the client side.

You can see its result here: http://pastebin.com/eZZTUNYA

Formatted version: http://pastebin.com/Gzg7jxT6

Short said: Dont even try to hide content. You cant.


If you still want to do, what your example did, you can do it with PHP as I said or in JavaScript directly. A PHP version would be:

$html = 'YOUR HTML CODE';
print urlencode($html);

Keep in mind, that because JavaScript has to decode it every time, it can cause higher loading times.

Manuel Mannhardt
  • 2,191
  • 1
  • 17
  • 23