如何防止浏览器窗口缩放

时间:2018-04-20 10:59:12

标签: javascript html internet-explorer

我想阻止浏览器的缩放功能。我的问题是我有一个OnRezise方法来控制页面中div的大小。这是按预期工作的。但是在缩放时我需要禁用此div的大小调整。是否可能。

我的代码就像这样

<body onresize="doResize();" onload="ctlLoad();">

我的Javascript就是这样

function doResize() {
objControl = document.getElementById("targetContainer");
container = document.getElementById("livePlayerContainer");

if (browserZoomLevel != (window.screen.deviceXDPI / 96)) {
    objControl.style.width = objControl.style.width + "px";
    objControl.style.height = objControl.style.height + "px";

    container.style.width = container.style.width + "px";
    container.style.height = container.style.height + "px";
    return;
}

//minHeight = 600;
minHeight = 420;
maxHeight = 1100;
maxWidth = 1000;

var winW = 0, winH = 0, ControlWidth = 637, ControlHeight = 480;
if (typeof (window.innerWidth) == 'number') {
    //Non-IE
    winW = window.innerWidth;
    winH = window.innerHeight;
} else
    if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        winW = document.documentElement.clientWidth;
        winH = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        winW = document.body.clientWidth;
        winH = document.body.clientHeight;
    }

// **NOTE - This is the main value to change. as you increase this value, it will add space to the bottom of the page
//          If we add more controls below the activeX, this value will need to be increased as well
ControlHeight = winH - 168;
ControlWidth = 4 * ControlHeight / 3;

//So it doesn't go out of bounds with the width
if (ControlWidth + 218 > winW) {
    ControlWidth = winW - 218;
    ControlHeight = 3 * ControlWidth / 4;
}

objControl.style.width = ControlWidth + "px";
objControl.style.height = ControlHeight + "px";

container.style.width = ControlWidth + "px";
container.style.height = ControlHeight + "px";

var num = parseInt($('#multiplexNumber').val());
ChangeDisplayMode(num, null);

}

我尝试使用此代码

保留所需的div大小
if (browserZoomLevel != (window.screen.deviceXDPI / 96)) {
    objControl.style.width = objControl.style.width + "px";
    objControl.style.height = objControl.style.height + "px";

    container.style.width = container.style.width + "px";
    container.style.height = container.style.height + "px";
    return;
}

但它不起作用。有人可以帮我解决这个问题吗?

0 个答案:

没有答案