User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 456,470 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,806 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2126 | Replies: 11 | Solved
Reply
Join Date: Jun 2008
Posts: 71
Reputation: Q8iEnG is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
Q8iEnG Q8iEnG is offline Offline
Junior Poster in Training

How to Disable (View Source) and (Ctrl+C) from a site?

  #1  
Aug 4th, 2008
Hi guys

Is there a chance to disable these two things from my site?
(View Source) and (Ctrl + C )

please, give me few minutes from your time and help, i'll be much more appreciated


thanks in advance
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2008
Location: Sweet India
Posts: 977
Reputation: Shanti Chepuru is on a distinguished road 
Rep Power: 2
Solved Threads: 90
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Posting Shark

Re: How to Disable (View Source) and (Ctrl+C) from a site?

  #2  
Aug 5th, 2008
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote  
Join Date: Jul 2008
Location: Sweet India
Posts: 977
Reputation: Shanti Chepuru is on a distinguished road 
Rep Power: 2
Solved Threads: 90
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Posting Shark

Re: How to Disable (View Source) and (Ctrl+C) from a site?

  #3  
Aug 5th, 2008
For this I use onKeyDown event. See the following code
that disables CTRL C and CTRL V.

Note that this is not enough to prevent COPY/PASTE
in a text field, since the user can use CTRL INS, SHIFT INS
or simply use the context menu (right click on text field).

  1. <html>
  2. <head>
  3. <script language="javascript">
  4.  
  5. function onKeyDown() {
  6. // current pressed key
  7. var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();
  8.  
  9. if (event.ctrlKey && (pressedKey == "c" ||
  10. pressedKey == "v")) {
  11. // disable key press porcessing
  12. event.returnValue = false;
  13. }
  14.  
  15. } // onKeyDown
  16.  
  17. </script>
  18. </head>
  19.  
  20. <body>
  21. <form name="aForm">
  22. <input type="text" name="aText" onkeydown = "onKeyDown()">
  23. </form>
  24. </body
  25. </html>
Last edited by Shanti Chepuru : Aug 5th, 2008 at 3:00 am. Reason: used code tags
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote  
Join Date: Jul 2008
Location: Sweet India
Posts: 977
Reputation: Shanti Chepuru is on a distinguished road 
Rep Power: 2
Solved Threads: 90
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Posting Shark

Re: How to Disable (View Source) and (Ctrl+C) from a site?

  #4  
Aug 5th, 2008
how to disable ctrl+c:
http://www.faqs.org/faqs/msdos-progr...ection-16.html

And
That shortcut is handled by the operating system. It never reaches the browser and so the browser has no opportunity to pass it to the web page.

IE only:

Add the following code to your BODY tag:

ondragstart="return false" onselectstart="return false"
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote  
Join Date: Jun 2008
Posts: 71
Reputation: Q8iEnG is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
Q8iEnG Q8iEnG is offline Offline
Junior Poster in Training

Re: How to Disable (View Source) and (Ctrl+C) from a site?

  #5  
Aug 5th, 2008
Thanks a lot you did helped me a lot that's nice from you

thanks a lot, much appreciated
Reply With Quote  
Join Date: Jul 2008
Location: Sweet India
Posts: 977
Reputation: Shanti Chepuru is on a distinguished road 
Rep Power: 2
Solved Threads: 90
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Posting Shark

Re: How to Disable (View Source) and (Ctrl+C) from a site?

  #6  
Aug 5th, 2008
Fine....
Last edited by Shanti Chepuru : Aug 5th, 2008 at 8:01 am.
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,628
Reputation: peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice peter_budo is just really nice 
Rep Power: 12
Solved Threads: 311
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: How to Disable (View Source) and (Ctrl+C) from a site?

  #7  
Aug 5th, 2008
As long you do not provide pure HTML site nothing is as it seems in source view...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, JAVAWUG (Java Web User Group), Coding the Architecture
Reply With Quote  
Join Date: Feb 2008
Location: Gurgaon India
Posts: 182
Reputation: nikesh.yadav is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 15
nikesh.yadav's Avatar
nikesh.yadav nikesh.yadav is offline Offline
Junior Poster

Re: How to Disable (View Source) and (Ctrl+C) from a site?

  #8  
Aug 6th, 2008
Shanti Chepuru

u done good work
Help as an alias

I think programming is great................
Go To My Home Page
Reply With Quote  
Join Date: Jun 2008
Posts: 71
Reputation: Q8iEnG is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
Q8iEnG Q8iEnG is offline Offline
Junior Poster in Training

Re: How to Disable (View Source) and (Ctrl+C) from a site?

  #9  
Aug 6th, 2008
Yeah, he did
Reply With Quote  
Join Date: Jul 2008
Location: Sweet India
Posts: 977
Reputation: Shanti Chepuru is on a distinguished road 
Rep Power: 2
Solved Threads: 90
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Posting Shark

Re: How to Disable (View Source) and (Ctrl+C) from a site?

  #10  
Aug 7th, 2008
thanks for ur compliments...
Originally Posted by Q8iEnG View Post
Yeah, he did

And im female....
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 2:25 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC