在IE7(jQuery/JS)中禁用页面缩放 [英] Disabling page zoom in IE7 (jQuery/JS)
本文介绍了在IE7(jQuery/JS)中禁用页面缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
鉴于可访问性,我知道这不是最好的选择,但是我确实有必要禁止用户使用IE7中的CTRL +缩放页面.
I know this is not the best thing to do in view of accessibility, but I have a genuine need to disable the user from zooming onto the page using CTRL+ in IE7.
我通过以下方式将其用于其他浏览器,但IE7似乎忽略了"return false":
I got it working for the other browsers the following way, but IE7 seems to ignore the "return false":
$(window).keydown(function (e) {
alert('key is down'); // this fires
return false; // but this has no effect in IE7!
});
推荐答案
这是更好且正确的方法:
This is better and correct way:
$(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');
}
});
});
这篇关于在IE7(jQuery/JS)中禁用页面缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文