首页 > 解决方案 > 如何从电子 BrowserWindow 对象获取当前 URL?

问题描述

我想知道browser-window的当前 URL 。有没有办法访问 BrowserWindow 的 window.location.href 属性或任何其他方式来获取它?

标签: javascriptelectron

解决方案


在主进程中,使用窗口的 webContents。getURL()方法:

[...]
win = new BrowserWindow({ /* options */});
win.loadFile('index.html');
console.log (win.webContents.getURL();)

请参阅:如何获取 BrowserWindow 的 url?


推荐阅读