How to apply css to the electron webview

Asked 2 years ago, Updated 2 years ago, 149 views

How do I embed a web page into an electron and assign my own style to it?

electron

2022-09-30 21:13

1 Answers

A method is provided.

http://electron.atom.io/docs/v0.36.8/api/web-view-tag/ #webviewinsertcssssss

In javascript running in an HTML file embedded with WebView, you can retrieve the WebView DOM object and use the above methods.

<html>
  <body>
    <webview id="webview" src="~~"/>
    <script>
      var webview= document.getElementById('webview');
      webview.insertCSS("~~");
    </script>
  </body>
</html>

Also, even if you specify BrowserWindow directly with loadURL, you can do the same with the webContents that BrowserWindow has.

var win=new BrowserWindow (width:800, height:600);
win.loadURL("~~");
win.webContents.insertCSS("~~");


2022-09-30 21:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.