Created
November 15, 2016 07:25
-
-
Save potato4d/5ba0989a2a2bc738143af79fd2d2e0b0 to your computer and use it in GitHub Desktop.
ElectronのWebviewにexecuteJavaScriptを利用した場合のコールバックについて ref: http://qiita.com/potato4d/items/9261908aba01f29c6f5f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const $ = e=>document.querySelector(e); | |
const webview = $("webview"); | |
webview.addEventListener("did-stop-loading", ()=>{ | |
webview.executeJavaScript( | |
`color:{$("#col_channels_bg").css("backgroundColor")}`, | |
false, | |
function(color){ | |
console.log(color); // rgb(100, 100, 100); | |
// 決してcolor.colorではなく、colorでアクセスすることになるので注意 | |
} | |
); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const $ = e=>document.querySelector(e); | |
const webview = $("webview"); | |
webview.addEventListener("did-stop-loading", ()=>{ | |
webview.executeJavaScript( | |
`return $("#col_channels_bg").css("backgroundColor")`, | |
false, | |
function(color){ | |
console.log(color); | |
} | |
); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
webview.openDevTools(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Uncaught SyntaxError: Illegal return statement |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment