admin 管理员组文章数量: 1086019
Can anyone tell me why the below wont work? Please forgive any mistakes I am new to all of this
HTML
<webview id="wv1" src="/" 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>
I'm trying to get it so that once the content within the webview has loaded the background is changed to red via CSS. Open to any alternatives or help with why the above wont work.
thanks
Can anyone tell me why the below wont work? Please forgive any mistakes I am new to all of this
HTML
<webview id="wv1" src="https://www.github./" 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>
I'm trying to get it so that once the content within the webview has loaded the background is changed to red via CSS. Open to any alternatives or help with why the above wont work.
thanks
Share Improve this question asked Mar 21, 2017 at 14:52 user3236169user3236169 1552 gold badges3 silver badges13 bronze badges 02 Answers
Reset to default 4It works for me using the following setup, basically just the electron quick start
Run as electron index.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./" 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>
Just to be sure you may want to use instead of dom-ready the DOMContentLoaded and instead of insertCss, insertRule.
var webview = document.getElementById('wv1');
webview.addEventListener('DOMContentLoaded', function() {
webview.insertRule('html,body{ background-color: #FF0000 !important;}',1)
});
However, if it won't work you may want to try
webview.querySelector(body) !== null
Inside the function.
hope it works.
本文标签: javascriptInject CSS into ltwebviewgt ChromeElectronHTMLCSSJSStack Overflow
版权声明:本文标题:javascript - Inject CSS into <webview> ChromeElectronHTMLCSSJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1743986567a2513960.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论