Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript to detect when a user saves the web page?

Can javascript detect when a user saves the web page to their local disks? Or is there a similar functionality in some other client side scripts?

like image 455
user231979 Avatar asked Dec 16 '14 22:12

user231979


4 Answers

You could watch the key commands for the combination of ctrl + s to be hit. But if the user chooses to save through the menu, there is no way to capture that.

like image 96
Shan Robertson Avatar answered Nov 09 '22 07:11

Shan Robertson


JavaScript cannot do this, nor any other client-side language. As a matter of fact, there are no server-side languages that can do that either. As others stated, you can watch for a keyboard combination, but there is (currently) no way to detect that.

like image 45
Drazzah Avatar answered Nov 09 '22 06:11

Drazzah


It can't - and maybe some browser extensions can do it but it's highly unpractical to even expect random users install those just for this.

But you could for example try with some other methods:

  • right click custom function - enabling saving custom save page (while loging to backend),
  • capturing CTRL+s (as mentioned by Juan Mendes),
  • having some sort of tracking on the page that is triggered only when page is not accessed via your domain (for example image on your server that is requested only with special conditions)...
  • offering PDF document for saving and measuring it's requests (via backend method)...

So - shortly - no 100% solution...

like image 1
nettutvikler Avatar answered Nov 09 '22 06:11

nettutvikler


As others have illustrated already; via CTRL + S but not via the menu command

Here's some jQuery that illustrates capture of the keystrokes:

$(document).keydown(function(e) {
    if (e.key === "s" && e.ctrlKey) {
        alert("user saved page");
    }
});
like image 1
Matthew Layton Avatar answered Nov 09 '22 07:11

Matthew Layton