Utilisateur:Delhovlyn/confirmExit.js

Un article de Wikipédia, l'encyclopédie libre.

Note : Après avoir publié la page, vous devrez forcer son rechargement pour voir les changements : Mozilla / Konqueror / Firefox : Shift-Ctrl-R, Internet Explorer / Opera : Ctrl-F5, Safari : Cmd-R.

var isChanged = false;
 
function confirmExit() {
  if (!document.getElementById("wpSave")) return;  // Teste si on est en cours de modification : si oui, OK ; si non, stop.
  document.getElementById("wpTextbox1").setAttribute("onchange", "javascript:isChanged = true;");
  window.onbeforeunload = function() {
    if (isChanged) return 'Votre contribution n\'a pas été sauvegardée.';
    };
  var array_boutons = new Array("wpSave", "wpPreview", "wpDiff");
  var nn;
  for (nn in array_boutons) {
    document.getElementById(array_boutons[nn]).setAttribute("onclick", "window.onbeforeunload = '';");
  }
  document.getElementById("editform").setAttribute("onsubmit", "window.onbeforeunload = '';");
}
addOnloadHook(confirmExit);