1

Possible Duplicates:
How to disable (View Source) and (Ctrl + C ) from my site
How to disable or encrypt “View Source” for my site

Is there a way to hide source code from all browsers, disabling the right click and removing the view source option in Mac and PC?

Community
  • 1
  • 1
Erik
  • 5,701
  • 27
  • 70
  • 119
  • 12
    Don't put it online. Heck, don't write it at all. Even someone who opens your HTML files locally can see the source code. – BoltClock Aug 27 '10 at 21:21
  • 1
    This has been discussed a thousand times already. – Jan K. Aug 27 '10 at 21:23
  • 1
    possible duplicate of [How to disable (View Source) and (Ctrl + C ) from my site](http://stackoverflow.com/questions/1037593/how-to-disable-view-source-and-ctrl-c-from-my-site) and http://stackoverflow.com/questions/1788539/how-to-disable-or-encrypt-view-source-for-my-site – Corbin March Aug 27 '10 at 21:25
  • 1
    No. Visually rendering the page is just another representation of the source code. Invisible source => invisible page. – Dirk Vollmar Aug 27 '10 at 21:35

5 Answers5

10

No, there isn't. There is always a way for users to view the source of your web page, because you already sent it to them. Even if they can't right click, what about a "View source" menu option? Even if you could disable that too, users could use something like wget which isn't a browser to retrieve your page source.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
3

No, anything processed client-side is visible client-side in one way or another.

You can disable the right-click through javascript but usually that's ineffective and annoying.

Any code you want hidden needs to be server-side.

McAden
  • 13,714
  • 5
  • 37
  • 63
2

No. If you put it on the web there is no way to hide your source code. You could obfuscate your js, but that's about your only option.

cam
  • 14,192
  • 1
  • 44
  • 29
2

No, the source (HTML) needs to be present in order for the browser to render.

Dustin Laine
  • 37,935
  • 10
  • 86
  • 125
0

You can disable viewing source code by posting nothing but an empty page. Well, theoretically the user will still be able to select “view source” but there won't be anything to view.

This requirement is mutually exclusive with disabling right click, however; if you add the JavaScript to disable right clicking then the user can gain access to the source code for the click-disabler! As it won't be effective on all browsers anyhow, I suggest just posting the empty page to keep your sources completely safe.

Arkku
  • 41,011
  • 10
  • 62
  • 84
  • Dumb question... How do you post an empty page and still make it function? is this a joke? – Erik Aug 27 '10 at 21:29
  • Any browser should be able to render the empty page correctly, i.e. produce the empty window, completely functional, although the background colour of the empty window will vary according to browser preferences. It's practically always white in modern graphical browsers, however. (Trying to change the background colour would again expose the source code you use for specifying the background colour.) – Arkku Aug 27 '10 at 21:33
  • On a philosophical note I think it could be argued that the empty source of the empty page is still the source code, which would therefore expose the fact that your page has an empty source. You could circumvent this e.g. by forbidding access to the empty page on the server, but the returned sever error might be considered limiting with regard to functionality + the user could possibly gain access to the source for the server's error page (if any). – Arkku Aug 27 '10 at 21:36