js實現禁止pc端瀏覽器縮放和獲取當前頁面瀏覽器的縮放大小

因爲瀏覽器菜單欄屬於系統軟件權限,沒發控制,咱們着手解決ctrl/cammond + +/- 或 Windows下ctrl + 滾輪 縮放頁面的狀況,只能經過js來控制了 下面是用juery和原生js實現的代碼: img

test測試test測試test測試test測試瀏覽器

獲取當前頁面瀏覽器的縮放大小: // 判斷pc瀏覽器是否縮放,若返回100則爲默認無縮放,若是大於100則是放大,不然縮小 function detectZoom (){ var ratio = 0, screen = window.screen, ua = navigator.userAgent.toLowerCase(); if (window.devicePixelRatio !== undefined) { ratio = window.devicePixelRatio; } else if (~ua.indexOf('msie')) { if (screen.deviceXDPI && screen.logicalXDPI) { ratio = screen.deviceXDPI / screen.logicalXDPI; } } else if (window.outerWidth !== undefined && window.innerWidth !== undefined) { ratio = window.outerWidth / window.innerWidth; } if (ratio){ ratio = Math.round(ratio * 100); } return ratio; }; //具體實現demo: 瀏覽器網頁內容的百分比縮放(按Ctrl和+號鍵或者-號鍵的縮放) 知乎客戶端
相關文章
相關標籤/搜索