views:

976

answers:

4

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  A: 

Try attaching keydown to document instead:

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

     alert('key is down');
     return false;
});
jimyi
Yeah, I tried that, return false is being ignored.
+1  A: 

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');
     }       
    });        
});
sasa
I tried that - but two two things. In IE7, the zoom is activated by pressing CTRL and the "+" and "-" keys. Even after i modified the keycode values in your code to the + and - keys (instead of arrows), it still does not seem to work. The alert fires, but return false is ignored and the browser still zooms the page.
You are right, zoom is CTRL + +/- :) Post is updated...
sasa
A: 

Hello, This script doesn't work in IE7 Why???

Vlad
A: 

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

equinoxe