官网:

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>

相关文章:

  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
  • 2021-12-06
  • 2021-08-26
  • 2022-01-15
  • 2022-12-23
猜你喜欢
  • 2021-09-15
  • 2021-12-05
  • 2021-11-29
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2021-06-15
相关资源
相似解决方案