electron 系统默认应用程序管理文件和url

官网:

https://www.electronjs.org/docs/api/shell

shell 模块提供与桌面集成相关的功能。

在用户的默认浏览器中打开 URL 的示例:

const { shell } = require('electron')

shell.openExternal('https://github.com')

注意:虽然shell可以在渲染器过程中使用该模块,但该模块在沙盒渲染器中将不起作用。

关于沙盒选项:

https://www.electronjs.org/docs/api/sandbox-option

使用默认浏览器打开链接

主进程中使用

const { shell } = require('electron');
shell.openExternal('http://www.baidu.com');

执行会自动打开百度

渲染进程中使用

<!DOCTYPE html>
<html lang="en">
<head>
    
    <title>shell</title>
</head>
<body>
<h1>shell</h1>
<button onclick="btnClick()">点击使用默认浏览器打开百度</button>
</body>
<script>
    const { shell } = require('electron').remote;

    function btnClick(){
        console.log('打开百度........');
        shell.openExternal('http://www.baidu.com');
    }
</script>
</html>
原文地址:https://www.cnblogs.com/makalochen/p/14516317.html