-
-
Save codebytere/a786242649a5d2e462c3328c905f0c9f to your computer and use it in GitHub Desktop.
browserview-reparent
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> | |
<link rel="stylesheet" type="text/css" href="./styles.css"> | |
</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>. | |
<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 {app, BrowserWindow, BrowserView} = require('electron') | |
const {once} = require('events') | |
async function main () { | |
await app.whenReady() | |
const width = 400 | |
const height = 300 | |
// Open two windows | |
const win1 = new BrowserWindow({ | |
title: 'Window-1', | |
x: 300, | |
y: 300, | |
width, | |
height, | |
}) | |
const win2 = new BrowserWindow({ | |
title: 'Window-2', | |
y: 300, | |
x: 300 + width, | |
width, | |
height, | |
}) | |
// Create BrowserView and append it to Window-1 | |
const view = new BrowserView() | |
win1.addBrowserView(view) | |
view.setBounds({ | |
x: 0, y: 0, width, height, | |
}) | |
// Change BrowserView's owner window to Window-2 (e.g. to move tab between windows) | |
win2.addBrowserView(view) | |
view.webContents.loadURL('https://electronjs.org') | |
await once(view.webContents, 'did-finish-load') | |
view.webContents.executeJavaScript('alert("Close this window")') | |
win1.on('closed', () => { | |
view.webContents.executeJavaScript('alert("first window got closed")') | |
}) | |
} | |
main() | |
.catch(error => { | |
console.error(error) | |
app.exit(1) | |
}) |
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
// Empty |
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
// This file is required by the index.html file and will | |
// be executed in the renderer process for that window. | |
// All of the Node.js APIs are available in this process. |
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
/* Empty */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment