Hide Your HTML Source

Sometimes you might not want to allow guests to your website to view the HTML source code. You can disable the right click context menu by using the following bit of code in your page:

<body oncontextmenu='return false;'>

You can use this feature to prevent users from right clicking and saving an image from your site. This is support by IE and Firefox. I have seen sites use similar functionality to this to pop up an alert with a copyright message is a user tries to right click on an image.

Keep in mind that a user can always disable JavaScript altogether, view the source from the application menu, and/or even save the whole HTML file onto his/her desktop and view the source from Notepad.

Related posts:

  1. The Anatomy of a JavaScript Bookmarklet
  2. Print HTML Using IE
  3. Dynamically Create HTML Elements with JavaScript
  4. CDATA With XSLT
  5. HTML FieldSet Tag

This entry was posted in HTML/XML, JavaScript, TechKnow. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Posted April 7, 2011 at 4:18 am | Permalink

    thanks it helps! :)

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*