gpt4 book ai didi

javascript - 内容(webview)没有填满应用程序窗口

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:02:01 26 4
gpt4 key购买 nike

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

function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
"min-width": 800,
"min-height": 500,
resize: true,
"use-content-size": true
});

// and load the index.html of the app.
mainWindow.loadURL('file://' + __dirname + '/index.html');

// Open the DevTools.
mainWindow.webContents.openDevTools();
// Set Window Resizable
mainWindow.isResizable(true);

// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
}

然后 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>

不幸的是,内容(webview)没有调整大小以填充可用空间,它具有全宽但高度保持在 150px,当我在检查器面板中手动设置不同的大小然后它会调整。我如何告诉 webview 它应该占用全部空间?百分比不起作用,即。

webview {
width:100%;
height:100%;
}

我已将以下代码添加到 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>

输出以下结果(高度始终为 150!)

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

最佳答案

您已将 webview 的高度设置为 100%,但没有为父级设置明确的高度(在本例中为 body )。提供 body 和明确的大小应该可以解决您的问题:

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

另见:

关于javascript - 内容(webview)没有填满应用程序窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35039240/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com