Skip to content

Instantly share code, notes, and snippets.

@Nkzn
Created December 28, 2018 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nkzn/8ac24383a9a97f578a2a537a57acf7cf to your computer and use it in GitHub Desktop.
Save Nkzn/8ac24383a9a97f578a2a537a57acf7cf to your computer and use it in GitHub Desktop.
ElectronのHTML側に定義したビューをNode.js側から利用するサンプル
<!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>
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