I have the below code to block the view source but its not working for me. Someone pls take a look and let me know. Thanks.


<script language="javascript">
 function onKeyDown() { 
 // current pressed key  
var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();  
 if (event.ctrlKey && (pressedKey == "c" ||                      
   pressedKey == "v")) 
{    // disable key press porcessing    
event.returnValue = false;  
} // onKeyDown



<DIV align=center>

<DIV align=center style="width: 927; height: 117">

<TABLE cellSpacing=0 cellPadding=0 width="859" border=0 height="106">

<TR class=header>
<TD vAlign=left height="78" width="829">


<TD colSpan=2 height="28" width="1109"><!--<table border='0' style="background:url() top repeat-x;" width='100%'>-->
<TABLE style="BORDER-RIGHT: #efefff 1px solid; BORDER-TOP: #efefff 1px solid; BORDER-LEFT: #efefff 1px solid; BORDER-BOTTOM: #efefff 1px solid" 
      cellSpacing=5 width="100%" border=0>
<TR class=header>
<table width="50%" border=0 bordercolor="#FF0000" >

<TD align = 'left' >
<a href = "../index.php" ><FONT face="Arial, Helvetica, sans-serif" 
            size=2><I>  <font color="#FFFFFF"><img src="BENGALIlist.BMP" alt="" width="137" height="39" /></font></I></a>


<form name="aForm"><input type="text" name="aText" onkeydown = "onKeyDown()"></form>

<table align = 'center' width = "55" border = "0" style = 'table-layout:fixed'>


<tr bgcolor = #00FF00>

<tr > <TD COLSPAN = "4"><A NAME="ny">  <font color = "red"> <b>New York Doctors</B></A> </TD>

<tr bgcolor = "#AFC7C7">
<td ALIGN = "left" valign = "top"><b> Doctor</b><br><br><br><br></td>
<td ALIGN = "left" valign = "top">Medicine, Dentist.</td>
<td ALIGN = "left" valign = "top">Address: 7017 37 ave. <br>nj</br><br> </td>

<tr bgcolor = "#AFC7C7">
<td ALIGN = "left" valign = "top"><b>Dr.  Hasan, MD </b><br><br></td>
<td ALIGN = "left" valign = "top">Board Certified.</td>
<td ALIGN = "left" valign = "top">Address: 3743 76th st.<br> nj<br><br></td>




Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

7 Years
Discussion Span
Last Post by akmwebtech

Don't try to stop people from viewing source. If someone wants to view source they can do it (Disable JavaScript). You are better off making sure your content is good and well written.


Your code is just to prevent copy and paste :)

like stbuchok said.. don't waste time protecting your source code.. if some one want's is.. it will get it..

but if you really wan't to do it.. I recommend using js and ajax like facebook do.. But that way your site wont be indexed by search engines..

Best regards



I am trying to develop a site so ppl can find list of contacts(docotrs/lawyers/travel agents). I simply wrote all in html. I am very new in WEB DEVELOPMENT. I want to block view source bc i dont want someone save the view source in notepad and make another site.i am spending lot of time collect all the information. and some thief get it just by clicking view source. not fair. :). Can i atleast make it hard for the thiefs to get my info? I mean to say can i at least disable CTRL+C? and When they see my view source, how can i throw bunch of junks in the code so they have to keep looking for the info? :)

PHP/MYSQL:Instead of writing in html, what about if i save the contacts in mysql database and have php script to pull the data from database. then users will get contacts by clicking submit from the home page. in this case, if ppl click view source, will they still see all data in notepad?



Have you thought that someone can just do a Save on the page? What about screen scraping? To get the most protection, turn everything into images, that way they have to type everything out (this is however an incredibly terrible idea).

You will not be able to stop people from stealing the data if it is front facing (meaning that there is no login needed to view the data). I would stop worrying about it and start worry about the functionality of the site and the look and feel. Make the user want to stay use you for ... whatever it is you do.


the only actual way to do that is by using flash.. and block the print screen key..
but even then I can still get the information for the page.. using a screen ocr..

It's almost.. impossible to hide something that is on-line.. :\


In Chrome it doesn't work if you assign it to the document, instead of an input element. But in any case, don't do it :)


'I am very new at web development"; yeah, guessed that,
with more experience you wouldnt ask the question
unless you built another google, big fat hairy deal
site isnt unique, the information is available from a hundred(at least) other sources
google maps provide routes to them all as well

every part of your site is in the user browser cache,
anyone who wants to can read it,
anyone who wants the code knows more than you do about how to get it

Edited by almostbob: n/a



<!DOCTYPE html>
    <script type="text/javascript">
        function key(event){
            var keyCode = ('which' in event) ? event.which : event.keyCode;
            alert ("key code: " + keyCode);
<body onkeyup="key(event);">


this doesn't work for you?!?!?

Edited by Dani: Formatting fixed

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.