Created
June 24, 2015 15:44
-
-
Save dannvix/dc0efdbb75bf79a79d1c to your computer and use it in GitHub Desktop.
Create Electron's BrowserWindow with dynamic HTML content
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
| // main.js for Electron | |
| var app = require("app"), | |
| BrowserWindow = require("browser-window"); | |
| app.on("window-all-closed", function() { | |
| app.quit(); | |
| }) | |
| var mainWindow = null; | |
| app.on("ready", function() { | |
| mainWindow = new BrowserWindow({ | |
| width: 800, | |
| height: 600, | |
| center: true, | |
| resizable: true, | |
| frame: true, | |
| transparent: false, | |
| }); | |
| mainWindow.setMenu(null); | |
| // create BrowserWindow with dynamic HTML content | |
| var html = [ | |
| "<body>", | |
| "<h1>It works</h1>", | |
| "</body>", | |
| ].join(""); | |
| mainWindow.loadUrl("data:text/html;charset=utf-8," + encodeURI(html)); | |
| mainWindow.openDevTools(); | |
| mainWindow.on("closed", function() { | |
| mainWindow = null; | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@dannix, but how to force electron to load scripts? Let's say if your dynamic html contains
<script src="./index.js"></script>