在IE7中禁用页面缩放(jQuery / JS)

我知道从可访问性来看这不是最好的事情,但我真的需要禁止用户在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'); } }); }); 

尝试将keydown附加到文档:

 $(document).keydown(function (e) { alert('key is down'); return false; }); 

如果最终用户的浏览器在访问您的页面之前已经拥有缩放集,那么这是毫无意义的。

简单的答案。 对于IE,你需要Event.stop(e); 而不是return 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. });