demo.html部分
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- <button id="btn">
打开新的窗口
</button>
<div>
</div> -->
<a id="aHref" href="https://www.baidu.com/">打开外部链接</a>
<script src="./render/openweb.js"></script>
</body>
</html>
JS部分:
const {shell} = require('electron');
const aHref = document.querySelector('#aHref');
aHref.onclick = function(e){
e.preventDefault();
let href = this.getAttribute('href');
shell.openExternal(href)
}