Catch browser's “zoom” event in JavaScript

前端 未结 16 1575
眼角桃花
眼角桃花 2020-11-22 05:45

Is it possible to detect, using JavaScript, when the user changes the zoom in a page? I simply want to catch a \"zoom\" event and respond to it (similar to window.onresize e

16条回答
  •  情歌与酒
    2020-11-22 05:51

    This works for me:

            var deviceXDPI = screen.deviceXDPI;
            setInterval(function(){
                if(screen.deviceXDPI != deviceXDPI){
                    deviceXDPI = screen.deviceXDPI;
                    ... there was a resize ...
                }
            }, 500);
    

    It's only needed on IE8. All the other browsers naturally generate a resize event.

提交回复
热议问题