2017-03-21 5 views
3

誰も私に以下の理由で問題がないと教えてもらえますか?私はWebViewの内のコンテンツが読み込まれた後背景はCSSを経由して赤に変化するようにそれを取得しようとしているこのCSSを入力する<webview>クロム/エレクトロン/ HTML/CSS/JS

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> 

のすべてに新しいです間違いはご容赦下さい。任意の選択肢を開くか、上記の理由が働かないことを助けてください。

おかげ

答えて

1
それは次のセットアップを使用して、私の作品

、基本的には電子quick start

実行electron index.jsとして

Result

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> 
1

ちょうどあなたがDOM対応DOMContentLoadedの代わりに、insertCss、insertRuleのinstaed使用することをお勧めします確かに。

var webview = document.getElementById('wv1'); 

webview.addEventListener('DOMContentLoaded', function() { 
    webview.insertRule('html,body{ background-color: #FF0000 !important;}',1) 
}); 

しかし、それはあなたが関数内

webview.querySelector(body) !== null 

を試してみたいことがあります動作しない場合。

希望します。

関連する問題