Prevent user from CTRL+C of the screen...

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
sblasic
Veteran Member
Posts: 53
Joined: 2021-02-22 15:55

Prevent user from CTRL+C of the screen...

Post by sblasic » 2023-02-09 09:22

Hi guys!

I was wondering how to prevent user of the database to just copy (CTRL +A & CTRL+C) the table on the screen?

I know how to do this in the basic HTML website - but where & what code to put in the AppGini project?

Can I put the CTRL+C blocking script only into: INDEX.HTML?

Below is the link on the CTRL + key blocking script I would use:

https://pastebin.com/qppZugBW

BTW - if you have a better solution (better script) - please post it here - thank you!!!

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Prevent user from CTRL+C of the screen...

Post by jsetzer » 2023-02-09 12:39

I'm pretty sure you cannot deny copying completely. You can block keyboard input, sure, but if users cannot use CTRL+C on the keyboard but want the data, there are still enough options like these:
  1. use keyboard or mouse for selecting text, then (right click) context menu item for copying
  2. in Windows use F10 key, then copy command
  3. save file as html and open it locally in any text editor. Copy from there.
  4. show sourcecode (CTRL+U) in browser and copy from there
  5. open developer tools (F12) and copy table from elements tab (or use inspect element and do the same)
  6. disable Javascript after page has been reloaded, then use CTRL+C
  7. take a screenshot + ocr (for example use the OCR tool built into screenshot-tool ShareX)
There will be more ways to get around your keypress-interception-code.

If you need something bulletproof, I think you cannot use HTML in a common browser.

But I'm very interested if someone here has a solution.

From my experience:
Years ago (decades, actually) a customer wanted to share price lists with his customers on the internet but didn't want them to download the lists for later use. He wanted them to always get latest price lists, not outdated ones. Other developer companies failed before, so did we on finding any bulletproof solution in HTML with standard browsers.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

sblasic
Veteran Member
Posts: 53
Joined: 2021-02-22 15:55

Re: Prevent user from CTRL+C of the screen...

Post by sblasic » 2023-02-09 13:03

@ jsetzer

Thank you for your feedback!

Yes, I know there are many ways to copy the content of the table in browser - even taking a screen shot is one way which could not be prevented...

Anyways, I want to prevent simple and easy "copy + paste"...

So, I wondering where to put the javascript code (I have put link to the code above)?

In the index.html or index.php... or someplace else?

Guys, I'm open to your suggestions - thank you!

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Prevent user from CTRL+C of the screen...

Post by jsetzer » 2023-02-09 14:13

hooks/header-extras.php could be a central place. Put javascript code in a <script/> tag.

If you need it for one table or several tables, hooks/TABLENAME-TV.js should work.

But remember that tables are lazy loaded in table views. Just in case you try to setup a keydown/keypress/keyup event listener on a table directly instead of attaching the listener to the document.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 352
Joined: 2013-03-21 04:37

Re: Prevent user from CTRL+C of the screen...

Post by peebee » 2023-02-10 04:12

While I haven't ever tried it for myself, a quick browse of Google returned this page with some very elementary jQuery examples (scroll down the page) that should be able to be added to hooks/header-extras.php or hooks/TABLENAME-TV.js to do the job:

"How to Disable Text Selection, Copy, Cut, Paste and Right-click on a Web Page"
https://www.w3docs.com/snippets/javascr ... -page.html

As Jan mentioned, very easy to override so it won't stop anything malicious but it should at least prevent the average user from using those functions (that is assuming the code works).

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 352
Joined: 2013-03-21 04:37

Re: Prevent user from CTRL+C of the screen...

Post by peebee » 2023-02-10 04:33

Code: Select all

<script>
      $j(document).ready(function() {
      //Disable cut copy paste
          $j('body').bind('cut copy paste', function(e) {
              e.preventDefault();
            });
      //Disable mouse right click
          $j("body").on("contextmenu", function(e) {
              return false;
            });
        });
</script>

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 352
Joined: 2013-03-21 04:37

Re: Prevent user from CTRL+C of the screen...

Post by peebee » 2023-02-10 05:24

Thought I'd better try it myself to save embarrassment, which I now have.

Doesn't seem to work in hooks/header-extras.php for some reason?

But if you add the following snippet to hooks/tablename-tv.js it does work nicely (obviously replace tablename with the actual table name and if the file doesn't exist, create it)

Code: Select all

      $j(document).ready(function() {
      //Disable cut copy paste
          $j('body').bind('cut copy paste', function(e) {
              e.preventDefault();
            });
      //Disable mouse right click
          $j("body").on("contextmenu", function(e) {
              return false;
            });
        });
That is for table view only. Same should work for detail view if you add it to hooks/tablename-dv.js

sblasic
Veteran Member
Posts: 53
Joined: 2021-02-22 15:55

Re: Prevent user from CTRL+C of the screen...

Post by sblasic » 2023-02-10 09:32

@ peebee & @jsetzer

Thank you guys very much for your detailed and precise answer(s)!

I'll try to implement this over the weekend - I'll let you know on Monday/Tuesday!

Have a great weekend - cheers!

sblasic
Veteran Member
Posts: 53
Joined: 2021-02-22 15:55

Re: Prevent user from CTRL+C of the screen...

Post by sblasic » 2023-02-13 14:16

peebee wrote:
2023-02-10 05:24
Thought I'd better try it myself to save embarrassment, which I now have.

Doesn't seem to work in hooks/header-extras.php for some reason?

But if you add the following snippet to hooks/tablename-tv.js it does work nicely (obviously replace tablename with the actual table name and if the file doesn't exist, create it)

Code: Select all

      $j(document).ready(function() {
      //Disable cut copy paste
          $j('body').bind('cut copy paste', function(e) {
              e.preventDefault();
            });
      //Disable mouse right click
          $j("body").on("contextmenu", function(e) {
              return false;
            });
        });
That is for table view only. Same should work for detail view if you add it to hooks/tablename-dv.js
Thank you!
It worked like a charm!

I'll be so free to contact you peebee and/or jsetzer if I had a paying job regarding online DB "tweeks" and related AppGini stuff!

So, if it's allowed on this forum - I'd ask you two for contact emails - thank you!
Have a great day!

Post Reply