How to get the url of the BrowserWindow?(如何获取 BrowserWindow 的 url?)
问题描述
这是一个非常基本的问题.在电子中,如何检查 BrowserWindow 的 url/文件名?
This is a pretty basic question. In electron, how do I check the url/filename of a BrowserWindow?
let win;
app.on('ready', () => {
win = new BrowserWindow();
win.loadFile(path.join(__dirname, 'public', 'main.html'));
win.on('closed', () => {
app.quit();
})
});
好吧,这么说,这是代码,说在不同的(添加:插入)浏览器窗口中发生某个事件后,我想从主浏览器窗口(win)获取 url.
Ok, so say, this is the code, say after a certain event happens in a different (add:insert) BrowserWindow, I want to get the url from the main BrowserWindow (win).
let addWin;
ipcMain.on('createAddWin', ()=>{
addWin = new BrowserWindow();
addWin.loadFile(path.join(__dirname, 'public', 'add.html'));
addWin.on('closed', () => {
addWin = null
});
ipcMain.on('add:insert', (e,insertObject) => {
//some event happens
//retrieve url from main window (win)
});
});
我该怎么做呢,我宁愿不必向 win 发送事件,然后通过 ipcRenderer 发送 url,尽管这绝对是可能的.
How do I go about this, I prefer to not have to send an event to the win to then send the url through ipcRenderer, though this is definitely possible.
推荐答案
可以使用 getURL() 窗口的 webContents 实例方法> 实例属性:
Getting the window's URL is possible by using the getURL() instance method of the window's webContents instance property:
let currentURL = win.webContents.getURL();
这篇关于如何获取 BrowserWindow 的 url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获取 BrowserWindow 的 url?


- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01