Frage

Is there a way to detect/intercept when the user tries to save the page? This would allow me to embed any external files properly and provide the user with a fully-functional offline app.

The other solution is embedding those resources from the beginning, but it consumes too many resources and and takes away some of the dynamic capability.

Any alternative that does not require any external libraries (including jQuery, I respect it, but it loads too much for this project) is acceptable.

War es hilfreich?

Lösung

There is no window.onsave event that I could find. However, you COULD listen for the ctrl+s keystroke which is easily intercepted.

var isCtrl = false;
document.onkeyup=function(e){
    if(e.keyCode == 17) isCtrl=false;
}

document.onkeydown=function(e){
    if(e.keyCode == 17) isCtrl=true;
    if(e.keyCode == 83 && isCtrl == true) {
        //run code for CTRL+S -- ie, save!
        return false;
    }
}

Code courtesy of: How do I capture a CTRL-S without jQuery or any other library?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top