我有两个 HTML 文件:index.html 和 Zoomerror.html。 该网站仅在浏览器缩放级别为 80% 时才能正常显示。有没有一种方法可以使用Javascript不间断地检测缩放级别,并在浏览器缩放级别从80%更改为其他级别时将页面从index.html重定向到zoomerror.html?我想不出任何代码可以做到这一点。
我尝试使用
window.devicePixelRatio
功能来实现此目的,但它只会导致页面不断刷新,即使缩放级别为 80%。
为了解决您的问题,我将提供一些 JavaScript 代码来检测当前浏览器大小以及下一步要做什么。此代码允许浏览器检测调整大小并相应地重定向页面。
// Get the current browser scale
var zoomLevel = Math.round(window.devicePixelRatio * 100);
// Agar masshtab 80% dan katta bo'lsa
if (zoomLevel >= 80) {
// Agar shkala 80% dan katta bo'lsa
window.location.href = 'index.html';
} else {
// redirect to zoomerror.html
window.location.href = 'zoomerror.html';
}