After Unity has packaged WebGL, edit the package-generated index.html file with a text editor
Modify the code inside the generated HTML <script Type= "Text/javascript" > function Reset () { var canvas = document.getElementById ("#canvas "); Canvas.height= Document.documentElement.clientHeight; Canvas.width = document.documentElement.clientWidth; Console.log (canvas.width); } </script>
<!DOCTYPE HTML><HTMLLang= "en -us"> <Head> <MetaCharSet= "Utf-8"> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"> <title>Unity WebGL Player | Avater</title> <Scriptsrc= "Build/unityloader.js"></Script> <Script> vargameinstance=Unityloader.instantiate ("Gamecontainer", "Build/ai_web.json"); </Script> <Scripttype= "Text/javascript"> functionReset () {varCanvas=document.getElementById ("#canvas"); Canvas.height=Document.documentElement.clientHeight; Canvas.width=Document.documentElement.clientWidth; Console.log (Canvas.width); } </Script> </Head> <Bodyonload= "Reset ()"onresize= "Reset ()"> <Divclass= "Webgl-content"style= "width:100%; height:100%" > <DivID= "Gamecontainer"style= "width:100%; height:100%"></Div> </Div> </Body></HTML>
Unity WebGL Window Adaptive