Utilisateur:Delhovlyn/confirmExit.js

Une page de Wikipédia, l'encyclopédie libre.
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;

Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
var isChanged = false;
function confirmExit()
  {
  document.getElementById("wpTextbox1").onchange = function(){ isChanged = true; };
  window.onbeforeunload = function() { if(isChanged) {return "Votre contribution n'a pas été sauvegardée.";} };
 
  var array_boutons = ["wpSave", "wpPreview", "wpDiff"];
  for (nn=0; nn<3; nn++)
    {
    document.getElementById(array_boutons[nn]).onclick = function(){ window.onbeforeunload = ''; };
    }
  document.getElementById("editform").onsubmit = function(){ window.onbeforeunload = ''; };
  }

if (mw.config.get('wgAction') == 'edit' || mw.config.get('wgAction') == 'submit')
  {addOnloadHook(confirmExit);}