谁能告诉我为什么以下不会工作?请原谅我对这一切都不熟悉的任何错误
<webview id="wv1" src="https://www.github.com/" style="display:inline-flex; width:100%; height:140px" nodeintegration></webview>
<script>
var webview = document.getElementById('wv1');
webview.addEventListener('dom-ready', function() {
webview.insertCSS('html,body{ background-color: #FF0000 !important;}')
});
</script>
我试图得到它,以便一旦webview中的内容加载后,背景将通过CSS更改为红色.对任何替代方案持开放态度或帮助解释上述原因不适用的原因.
谢谢
解决方法:
它适用于我使用以下设置,基本上只是电子quick start
作为电子索引运行.js
index.js
const { app, BrowserWindow } = require('electron')
const path = require('path')
const url = require('url')
let win
function createWindow() {
win = new BrowserWindow({ width: 800, height: 600 })
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
win.webContents.openDevTools()
win.on('closed', () => {
win = null
})
}
app.on('ready', createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (win === null) {
createWindow()
}
})
的index.html
<webview id="wv1" src="https://www.github.com/" style="display:inline-flex; width:100%; height:140px" nodeintegration></webview>
<script>
var webview = document.getElementById('wv1');
webview.addEventListener('dom-ready', function () {
webview.insertCSS('html,body{ background-color: #FF0000 !important;}')
});
</script>