Created
December 28, 2018 06:03
-
-
Save Nkzn/8ac24383a9a97f578a2a537a57acf7cf to your computer and use it in GitHub Desktop.
ElectronのHTML側に定義したビューをNode.js側から利用するサンプル
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Hello World!</title> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
<!-- All of the Node.js APIs are available in this renderer process. --> | |
We are using Node.js <script>document.write(process.versions.node)</script>, | |
Chromium <script>document.write(process.versions.chrome)</script>, | |
and Electron <script>document.write(process.versions.electron)</script>. | |
<div> | |
<button id="hoge">click me!</button> | |
</div> | |
<script> | |
// You can also require other files to run in this process | |
require('./renderer.js') | |
</script> | |
</body> | |
</html> |
This file contains 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 fs = require('fs'); // 標準ライブラリのファイル操作モジュールを呼び出す | |
// HTMLで定義したボタンをJS側に持ってくる | |
const hogeButton = document.getElementById("hoge"); | |
hogeButton.onclick = function() { | |
// ファイル一覧を表示する | |
fs.readdir('.', function(err, files) { | |
console.log(files); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment