J'ai une activité qui a 2 étapes, chaque étape a propre vue, l'étape 2 commence lorsque la première étape est terminée, et l'utilisateur est en deuxième vue, à l'étape 2, l'utilisateur ne devrait pas être capable de cliquer sur le bouton . peut-être que ce sera bien si je peux montrer un message à l'utilisateur, mais je ne sais pas comment le faire.mvc, Comment éviter de cliquer sur le bouton de retour du navigateur?
0
A
Répondre
0
Pour désactiver le bouton de retour, vous pouvez utiliser le code suivant sur la deuxième page.
window.onload = function() {
if (typeof history.pushState === "function") {
history.pushState("jibberish", null, null);
window.onpopstate = function() {
history.pushState('newjibberish', null, null);
// Handle the back (or forward) buttons here
// Will NOT handle refresh, use onbeforeunload for this.
};
}
else {
var ignoreHashChange = true;
window.onhashchange = function() {
if (!ignoreHashChange) {
ignoreHashChange = true;
window.location.hash = Math.random();
// Detect and redirect change here
// Works in older FF and IE9
// * it does mess with your hash symbol (anchor?) pound sign
// delimiter on the end of the URL
}
else {
ignoreHashChange = false;
}
};
}
}