A Practical Javascript script that disables right-click, selection, drag, and clear clipboard, and disables saving webpages as files

Source: Internet
Author: User

A Javascript script that disables right-click, select, drag, clear clipboard, and save a webpage as a prohibited object.

 

It is quite common. If you do not want to write it, copy it and use it directly without other settings.

  1. <Script language = "JavaScript">
  2. <! --
  3. ************* **************
  4. If (window. Event)
  5. Document. captureevents (event. mouseup );
  6. Function nocontextmenu ()
  7. {
  8. Event. cancelbubble = true
  9. Event. returnvalue = false;
  10. Return false;
  11. }
  12. Function norightclick (E)
  13. {
  14. If (window. Event)
  15. {
  16. If (E. Which = 2 | E. Which = 3)
  17. Return false;
  18. }
  19. Else
  20. If (event. Button = 2 | event. Button = 3)
  21. {
  22. Event. cancelbubble = true
  23. Event. returnvalue = false;
  24. Return false;
  25. }
  26. }
  27. ************ ***************
  28. Function noselect ()
  29. {
  30. Return false;
  31. }
  32. ************ ***************
  33. Function nodragstart ()
  34. {
  35. Return false;
  36. }
  37. // ************************* Clear the clipboard ************ *************
  38. Function keydown ()
  39. {
  40. VaR iekey = event. keycode;
  41. // Alert (iekey );
  42. If (iekey = 42)
  43. {
  44. // Window. clipboardData. setdata ('img ','')
  45. Window. clipboardData. cleardata ();
  46. }
  47. }
  48. // -->
  49. </SCRIPT>
  50. <! -- Disable saving a webpage as -->
  51. <NoScript> <IFRAME src = "*. htm"> </iframe> </NoScript>
  52. <! -- Disable saving a webpage as -->
  53. <NoScript> <IFRAME src = "*. htm"> </iframe> </NoScript> <script language = JavaScript>
  54. Document. oncontextmenu = nocontextmenu;
  55. Document. onmousedown = norightclick;
  56. Document. ondragstart = nodragstart;
  57. Document. onselectstart = noselect;
  58. Document. onselect = Document. selection. Empty ();
  59. Document. onkeydown = keydown;
  60. </SCRIPT>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.