Reputation: 61
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?
Upvotes: 6
Views: 2533
Reputation: 42260
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");
}
});
Upvotes: 1
Reputation: 604
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...
Upvotes: 1
Reputation: 7771
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.
Upvotes: 1
Reputation: 2742
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.
Upvotes: 6