简体   繁体   中英

Firefox 78.0.1 Responsive Design Mode not returning correct value for window.innerWidth after screen rotation

Is this a firefox bug or am I messing something up?

If I use chrome or even firefox on a real device (eg Android), there is no issue, it seems to only affect Firefox's Responsive Design Mode.

Here's the complete code required to replicate the issue:

<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" id="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
</head>
<body>

<script>
var pageInPortraintMode;

// Prevent keyboard from squeezing the entire UI
addEventListener("load", function() {
  pageInPortraintMode = window.innerHeight > window.innerWidth;
  document.getElementById("viewport").setAttribute("content", "width=" + window.innerWidth + ", height=" + window.innerHeight + ", initial-scale=1.0, maximum-scale=1.0, user-scalable=0");
})

// Listen to window resizes to detect orientation changes
window.addEventListener("resize", windowSizeChanged);

function windowSizeChanged() {
  alert(window.innerWidth + "x" + window.innerHeight);
  if (((pageInPortraintMode === true) && (window.innerHeight < window.innerWidth)) || ((pageInPortraintMode === false) && (window.innerHeight > window.innerWidth))) {
    pageInPortraintMode = window.innerHeight > window.innerWidth;
    document.getElementById("viewport").setAttribute("content", "width=" + window.innerWidth + ", height=" + window.innerHeight + ", initial-scale=1.0, maximum-scale=1.0, user-scalable=0");
  }
}
</script>

<div style="width:100%; height:100%; background-color:#000; position:fixed; left:0; top:0"></div>

</body>
</html>

To replicate enter Responsive Design Mode (Ctrl+Shift+M), load the html and then press the "Rotate Viewport" button.

It appears this is a reproducible firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=1650024

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM