在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. });
- Jquery scrollTo在IE7中出现问题
- Internet Explorer显示e.which为undefined
- 函数animate()中backgroundposition的扩展名在IE7或IE8中不起作用
- 选择后,jquery ui datepicker在IE7中不会消失
- 剪贴板IE 8和7中没有Jquery ZeroClipboard或Zclip
- Ajax文件上传在IE7中不起作用
- IE7和IE6中的jQuery .ajax方法无法正常工作,但在Firefox中工作正常
- 如何仅以编程方式为Internet Explorer 7关闭JavaScript?
- jQuery选择器无法在Windows Phone 7上运行