Javascript 禁用IE7中的页面缩放(jQuery/JS)
我知道从可访问性的角度来看,这不是最好的做法,但我确实需要禁用用户在IE7中使用CTRL+缩放页面 我通过以下方式让它适用于其他浏览器,但IE7似乎忽略了“return false”:Javascript 禁用IE7中的页面缩放(jQuery/JS),javascript,jquery,internet-explorer-7,zooming,Javascript,Jquery,Internet Explorer 7,Zooming,我知道从可访问性的角度来看,这不是最好的做法,但我确实需要禁用用户在IE7中使用CTRL+缩放页面 我通过以下方式让它适用于其他浏览器,但IE7似乎忽略了“return false”: 请尝试将keydown附加到文档: $(document).keydown(function (e) { alert('key is down'); return false; }); 请尝试将keydown附加到文档: $(document).keydown(function (e) {
请尝试将keydown附加到文档:
$(document).keydown(function (e) {
alert('key is down');
return false;
});
请尝试将keydown附加到文档:
$(document).keydown(function (e) {
alert('key is down');
return false;
});
这是更好和正确的方法:
$(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');
}
});
});
这是更好和正确的方法:
$(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');
}
});
});
答案很简单。对于IE,您需要
Event.stop(e)
而不是返回false代码>简单答案。对于IE,您需要Event.stop(e)
而不是返回false代码>我没有IE7在ATM上测试,但这应该可以
$(window).keydown(function (e) {
alert('key is down'); // this fires
e.preventDefault(); // This is a standard jQuery way of
// preventing the default action
return false; // Therefore you shouldn't need this.
});
我没有IE7在ATM机上测试,但这个应该可以
$(window).keydown(function (e) {
alert('key is down'); // this fires
e.preventDefault(); // This is a standard jQuery way of
// preventing the default action
return false; // Therefore you shouldn't need this.
});
如果最终用户的浏览器在访问您的页面之前已经设置了缩放,那么这是没有意义的。如果最终用户的浏览器在访问您的页面之前已经设置了缩放,那么这是没有意义的。我试过了,但有两件事。在IE7中,按CTRL键和“+”和“-”键可以激活缩放。即使在我将代码中的keycode值修改为+和-键(而不是箭头)之后,它似乎仍然不起作用。警报会触发,但return false会被忽略,浏览器仍会缩放页面。在IE7中,按CTRL键和“+”和“-”键可以激活缩放。即使在我将代码中的keycode值修改为+和-键(而不是箭头)之后,它似乎仍然不起作用。警报将触发,但返回false将被忽略,浏览器仍会缩放页面。