Javascript to detect when a user saves a webpage?

Can javascript detect when a user is saving a web page to their local drives? Or is there similar functionality in some other client-side scripts?

+3


source to share


4 answers


You can see the key commands for the combination ctrl + s

. But if the user chooses to save through the menu, then there is no way to grab it.



+5


source


JavaScript cannot do this, nor any other client-side language. In fact, there are no server-side languages ​​that can do this. As others have said, you can observe the keyboard shortcut, but there is currently no way to detect it.



+1


source


It can't - and maybe some browser extensions can do it, but it's very impractical even if casual users install them just for that.

But you could, for example, try other methods:

  • custom function of the right mouse button - enable saving the custom save page (when entering the backend),
  • grabbing CTRL + s (as mentioned by Juan Mendes),
  • has some sort of on-page tracking that only fires when the page is not accessible via your domain (like an image on your server that is only requested with specific conditions) ...
  • offers a PDF document to save and measure its requests (via a backend method) ...

So - soon - there is no 100% solution ...

+1


source


As others have already shown; via CTRL+ S, but not via menu command

Here's some jQuery that illustrates capturing keystrokes:

$(document).keydown(function(e) {
    if (e.key === "s" && e.ctrlKey) {
        alert("user saved page");
    }
});

      

0


source







All Articles