Disabling page zoom in IE7 (jQuery/JS)

随声附和 提交于 2019-12-12 01:30:54

问题


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.

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!
});

回答1:


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');
        }                  
    });                    
});



回答2:


Try attaching keydown to document instead:

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

     alert('key is down');
     return false;
});



回答3:


This is pointless if the end user's browser already has the zoom set before visiting your page.




回答4:


simple answer. for IE, you need Event.stop(e); instead of return false;




回答5:


I don't have IE7 to test on ATM but this should do it

$(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.
});


来源:https://stackoverflow.com/questions/946284/disabling-page-zoom-in-ie7-jquery-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!