0

我知道考虑到可访问性,这不是最好的做法,但我确实需要禁止用户在 IE7 中使用 CTRL+ 放大页面。

我通过以下方式让它适用于其他浏览器,但 IE7 似乎忽略了“return false”:

$(window).keydown(function (e) {

     alert('key is down');   // this fires          
     return false;          // but this has no effect in IE7!
});
4

5 回答 5

2

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');
        }                  
    });                    
});
于 2009-06-03T18:45:53.987 回答
1

如果最终用户的浏览器在访问您的页面之前已经设置了缩放,那么这是没有意义的。

于 2012-08-22T18:54:02.243 回答
1

尝试将 keydown 附加到文档:

$(document).keydown(function (e) {

     alert('key is down');
     return false;
});
于 2009-06-03T18:19:15.757 回答
0

我没有 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.
});
于 2012-07-13T13:41:21.597 回答
0

简单的答案。对于 IE,你需要Event.stop(e);而不是return false;

于 2010-10-13T22:14:06.837 回答