如何获取BrowserWindow的网址? [英] How to get the url of the BrowserWindow?

查看:231
本文介绍了如何获取BrowserWindow的网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常基本的问题。在电子方面,如何检查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();
    })
});

好,所以,这就是代码,比如说某个事件发生在另一个事件之后(添加:insert)BrowserWindow,我想从主BrowserWindow(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)
});

}); 

我该怎么做,我宁愿不必再向胜利发送事件通过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()实例方法docs / api / browser-window#winwebcontents rel = noreferrer> 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的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆