user231979
user231979

Reputation: 61

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?

Upvotes: 6

Views: 2533

Answers (4)

Matthew Layton
Matthew Layton

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

nettutvikler
nettutvikler

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:

  • 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...

Upvotes: 1

Ian Hazzard
Ian Hazzard

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

Shan Robertson
Shan Robertson

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

Related Questions