Why does document.documentElement.clientWidth sometimes get 0?

Mobile project, you need to set how many pixels the 1rem is through js, but the document.documentElement.clientWidth that the device width document.documentElement.clientWidth gets in the Mobile QQ chat dialog box is occasionally 0. There will be no problem in the real QQ Browser. I don"t know what the browser in Mobile QQ"s chat dialog is.

If you change

to document.body.clientWidth, you will occasionally get 0

.
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>Document</title>
</head>
<body>
   <script>
        window.onload=function () {
            var remSize = document.documentElement.clientWidth
        }
</script> 
</body>
</html>

< H2 > problem recurrence < / H2 >

there is no QQ Browser, ie browser. Switch the kernel to ie5,.
document.documentElement.clientWidth is always 0

. < H2 > ideas < / H2 >

can you solve this problem with jQuery, such as
$("body"). Width ()
test).
so check the jQuery source code

clipboard.png



clipboard.png


I have the same problem now, not QQ Browser. It's the webview, of the company APP. The weird thing is. This happens only on one of the pages. I wonder, too.

Menu