我知道考虑到可访问性,这不是最好的做法,但我确实需要禁止用户在 IE7 中使用 CTRL+ 缩放页面。
我通过以下方式使其适用于其他浏览器,但 IE7 似乎忽略了“return false”:
$(window).keydown(function (e) {
alert('key is down'); // this fires
return false; // but this has no effect in IE7!
});
最佳答案
这是更好、更正确的方法:
$(document).ready(function() {
var ctrl = false;
$(document).keydown(function(e){
// disable ctrl + +/-
if(ctrl && (e.keyCode == 107 || e.keyCode == 109)) {
alert('Zoom is disabled!');
return false;
}
if(e.keyCode == 17) {
ctrl = true;
// disable ctrl + scroll
$(document).bind('scroll', function() {
if(ctrl) {
alert('Zoom is disabled!');
return false;
}
});
}
})
$(document).keyup(function(e) {
if(e.keyCode == 17) {
ctrl = false;
$(document).unbind('scroll');
}
});
});
关于javascript - 在 IE7 中禁用页面缩放 (jQuery/JS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/946284/