2
I made the following script
$(document).ready(function () {
$('html').keydown(function (e) {
if (e.keyCode == 8)
{
ConfirmarVolta();
}
});
});
function ConfirmarVolta() {
if (confirm("Deseja voltar a tela inicial de cadastro de pedido? O progresso no pedido atual será perdido.")) {
location.href = "pedidoInserir.aspx";
} else {
return false;
}
}
And I hoped that by clicking 'cancel' on the popup, the screen would not go back. I separated the function of the trigger from pressing the Backspace key because it is used elsewhere in the code. How can I cancel Backspace action if the user does not confirm?
If you want to avoid browsing out of the page I think you have to cancel on the keydown, otherwise the keyup is too late.
– Sergio
@Sergio I changed to keydown. Regardless of that, I still keep the same problem. Despite the 'Return false', it performs the Backspace action
– Rafael Barbosa
You have to give
return
... forehead:return ConfirmarVolta();
– Sergio