2016-02-27 35 views
2

我想在我的electron應用程序中加載webview,然後調整對象內容的樣式。無論是通過JS還是CSS都無關緊要,我只想在webview內部能夠使用.hide()visibility: none元素。是否可以更改webview內容的樣式?

這可能嗎?事實證明很難發現。謝謝!

回答

1

我假設你運行的是最新版本的電子,因此基於網頁視圖documentation我想你可以試試這個:

插入CSS

//Append CSS code do page 
var myWebview = ;// your webview definition 
myWebview.insertCSS("body{background:#000}"); 

或者你可以使用運行JavaScript代碼executeJavascriptCode

var myWebview = ;// your webview definition 
myWebview.executeJavaScript("$('.mySelector').hide();"); 

但在這兩種情況下,我建議你閱讀文件內容,並把它作爲函數參數或使用executeJavascriptCode將您的文件附加到您的webview。檢查下面的例子:

// appending javascript code 
var scriptPath = __dirname + '/path/to/script.js'; 
var myWebview = ;// your webview definition 
myWebview.executeJavaScript('document.write(\'<script src="' + scriptPath + '"></script>\');'); 

// appending CSS code 
var cssPath = __dirname + '/path/to/stylesheet.js'; 
var myWebview = ;// your webview definition 
myWebview.executeJavaScript('document.write(\'<link rel="stylesheet" type="text/css" href="' + cssPath + '">\');'); 

希望它有幫助。

祝你好運!

+0

是的,我看到了,不適合我。 :( – Sjael

+0

你能爲我發佈一些代碼嗎?比將更容易檢查發生了什麼 –

相關問題