l'action onkeypress sous IE
Bonjour,
voici ce petit script qui me permet d'annuler l'action de la touche suppr afin de ne pas être redirigé vers la page précédente. Cela marche sous Firefox, mais par sous IE pouvez vous m'aider?
Merci.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| <script type="text/javascript">
var touche;
function lettreTouchee(e)
{
if(window.event) // IE
{
touche = e.keyCode;
}
else if(e.which) // Netscape/Firefox/Opera
{
touche = e.which;
}
}
NavName = navigator.appName;
if ( NavName.substring(0,3)=="Mic") { // IE
element.onkeypress = lettreTouchee(event);
}
else { // Firefox
document.onkeypress = lettreTouchee;
}
window.onbeforeunload = function (e) {
if (touche==8) {
if (event) { // For IE and Firefox
touche=1;
e.returnValue = '';
}
// For Safari
touche=1;
return '';
}
};
</script> |
intercepter la touche backspace
Ca n'a pas l'air de fonctionner sous IE8 :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>intercepter la touche backspace</title>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<style type="text/css">
* {margin:0;padding:0;}
body {margin:10px;background:#000;color:#ddd;font-size:1em;font-family:Helvetica, Arial, sans-serif;}
</style>
</head>
<body>
<p>Ce code n'a pas l'air de fonctionne sous IE8.</p>
<script type="text/javascript">
<!--
var FC = {
Evenement: {
evenements: [],
ajouter: function(elm, evt, fn) {
var fni = function(e) { // prévient le comportement par défaut
if (fn(e)===false) { // false explicitement car peut être undefined en cas de délégation d'évènement
if (e.preventDefault) { e.preventDefault(); }
else { e.returnValue = false; }
}
};
if (document.addEventListener) { elm.addEventListener(evt, fni, false); }
else if (document.attachEvent) { elm.attachEvent("on" + evt, fni); }
FC.Evenement.evenements.push([elm, evt, fni]);
}
}
}
FC.Evenement.ajouter(document, "keypress", function(e) {
var t = e.which || e.keyCode;
if (t===8) { return false;}
});
//-->
</script>
</body>
</html> |