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?
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.
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.
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:
So - shortly - no 100% solution...
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");
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With