Javascript 内容(webview)不会填满应用程序窗口

Javascript 内容(webview)不会填满应用程序窗口,javascript,css,webview,electron,Javascript,Css,Webview,Electron,我正在试用electron来创建一个独立版本的网站,我有这个main.js(摘录) 然后index.html如下所示: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> body { margin: 0; padding:

我正在试用electron来创建一个独立版本的网站,我有这个main.js(摘录)

然后index.html如下所示:

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        body {
            margin: 0;
            padding: 0;
            background-color: #6e6e6e;
        }
        webview {
            display: block;
        }

    </style>
</head>

<body>
    <webview src="build/index.html" disablewebsecurity></webview>
</body>

</html>
我已将以下代码添加到
index.html

<script>
    function onResize() {
        var height = document.body.clientHeight;
        var width = document.body.clientWidth;
        console.log("onResize", arguments, width, height);
    }
    addEventListener('resize', onResize);

</script>

您已经将
webview
的高度设置为
100%
,但没有为父视图(在本例中为
主体
)设置明确的高度。给出
主体
和明确的大小可以解决您的问题:

body {
    width: 100vw;
    height: 100vh;
}
另见:

<script>
    function onResize() {
        var height = document.body.clientHeight;
        var width = document.body.clientWidth;
        console.log("onResize", arguments, width, height);
    }
    addEventListener('resize', onResize);

</script>
onResize [Event] 216 150
index.html:27 onResize [Event] 216 150
index.html:27 onResize [Event] 1096 150
index.html:27 onResize [Event] 1096 150
index.html:27 onResize [Event] 1096 150
index.html:27 onResize [Event]                1080 150
        0: Event
            bubbles: true
            cancelBubble: false
            cancelable: false
            currentTarget: null
            defaultPrevented: fals
            eeventPhase: 0
            isTrusted: false
            isTrusted: false
            newHeight: 150
            newWidth: 1080
            path: Array[5]
            returnValue: true
            srcElement: webview
            target: webview
            timeStamp: 1453905541457
            type: "resize"__proto__: Event
            callee: onResize()
            length: 1
            Symbol(Symbol.iterator): values()
            __proto__: Object
body {
    width: 100vw;
    height: 100vh;
}