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

标签 javascript jquery internet-explorer-7 zooming

我知道考虑到可访问性,这不是最好的做法,但我确实需要禁止用户在 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');
        }                  
    });                    
});

关于javascript - 在 IE7 中禁用页面缩放 (jQuery/JS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/946284/

相关文章:

javascript - 如何根据日期对 JavaScript 中的对象进行排序

php - 在javascript函数中增加php变量

javascript - jquery 无法获取字符串数组

JSON对象内的Javascript搜索

javascript - 在 IE7/IE8 中获取尾随逗号(在 JavaScript 中)

javascript - IE7模态对话框滚动条重叠内容

javascript - 如何在动态表中创建唯一的ID?

javascript - 你能写一个只被 GoogleBot 触发的 Firebase 函数吗?

html - Internet Explorer 7 css 颜色和边框冲突

Javascript jQuery ajax