渲染进程调用
window.open("http://example.com")
时,是否可以在主进程中判断外部URL是否加载成功?
类似...
mainWindow.webContents.on('did-url-load', () => {
// Do something
});
mainWindow.webContents.on('did-url-loading-failed', () => {
// Do something
});
在 MDN 的 Window.open() 页面上:
一个 WindowProxy 对象,它基本上是代表新创建窗口的 Window 对象的薄包装,并具有其所有可用功能。如果无法打开窗口,则返回值为 null。
所以,我认为你应该检查 window.open 的返回值:
var dir = 'https://www.url.com';
var newWindow = window.open(url, 'main');
if (newWindow== null) {
// Failed
} else {
// Success
}