컴퓨터/Electron

Electron HTML 보여주기

sayyesdoit 2023. 4. 24. 15:03

1. main.js

const { BrowserWindow } = require('electron');
const path = require('path');

const mainWindow = new BrowserWindow({ width: 800, height: 600 });

const data = { name: 'John Doe', age: 30 }; // 전달할 데이터 객체

mainWindow.loadFile(path.join(__dirname, 'index.html'), { query: data });

  전달할 데이터가 없다면, { query: data } 는 생략 가능하다.

2. index.html 안의 index.js

const params = new URLSearchParams(window.location.search);
const name = params.get('name');
const age = params.get('age');