Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable zooming of the page in desktop web browsers using Javascript/Jquery [duplicate]

Possible Duplicate:
How to detect page zoom level in all modern browsers?

var obj=document.body;  // obj=element for example body
// bind mousewheel event on the mouseWheel function
if(obj.addEventListener)
{
    obj.addEventListener('DOMMouseScroll',mouseWheel,false);
    obj.addEventListener("mousewheel",mouseWheel,false);
}
else obj.onmousewheel=mouseWheel;

function mouseWheel(e)
{
    // disabling
    e=e?e:window.event;
    if(e.ctrlKey)
    {
        if(e.preventDefault) e.preventDefault();
        else e.returnValue=false;
        return false;
    }
}

I am developing a web app and all ui element will be not in a correct order if user zoom in / zoom out . So, are there any way to prevent it? I have think of some way to do it but is it possible ?

1) Get the screen resolution of the user. When the window size is change (either width or height), return the window width/height to screen width /height.

2) bind the mouse scroll event or keyboard event to nothing. (Refer to above demo code) , but what if the user click on the browser and select zoom in ?

Thanks

like image 899
user782104 Avatar asked Jan 14 '23 16:01

user782104


1 Answers

    var zoomlevel=1;

    $("body").dblclick(function(ev) {
        zoomlevel = zoomlevel == 1 ? 2 : 1;



        $(this).css({
            "-moz-transform":"scale("+zoomlevel+")",
            "-webkit-transform":"scale("+zoomlevel+")",
            "-o-transform":"scale("+zoomlevel+")",
            "-ms-transform":"scale("+zoomlevel+")"
        });


    });
like image 126
İbrahim Altınoluk Avatar answered Feb 17 '23 11:02

İbrahim Altınoluk