Hi,

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.

<html>

<head>
<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
 </script>

</head>

<body>

<DIV align=center>


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

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

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

   

<TR>
<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>
<TBODY>
        
      
<TR class=header>
</TR>
</TBODY>
</TABLE>
</div>
<br>
<table width="50%" border=0 bordercolor="#FF0000" >

<tr> 
<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>
</TD></TR>




</table>





<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>
<th>Name</th>
<th>Specialty</th>
<th>Address/Contact</th>
</tr>

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

<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>


<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>
</tr>



</table>

</body>

</html>
Member Avatar for stbuchok

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

Thanks.

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?

THX.

Member Avatar for stbuchok

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.

bangla,
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.. :\

You can't block the print screen key, and be happy it is like that.

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

twiss:

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


</body>
</html>

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

Yes it does, but it cannot be cancelled (return false and the like don't work).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.