Electron提供了webview标签,用来嵌入Web页面。
它作用上类似于HTML里的iframe标签,但跑在进程中,主要出于安全性考虑。它不拥有渲染进程的权限,并且应用和嵌入内容之间的交互全部都是异步的.因为这能保证应用的安全性不受嵌入内容的影响。
main.js
webPreferences: {
webviewTag: true, // 开启webview
}
在其他脚本执行之前预加载一个指定的脚本。
渲染进程:
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>父窗口</h1>
<div><button onclick="confirm()">确认</button></div>
<webview src="http://www.baidu.com" preload="./render.js"></webview>
</body>
</html>
render.js
setTimeout(function(){
alert(document.getElementById("su").value);
document.getElementById("su").onclick = function(){
alert("您点击了搜索按钮!");
}
}, 5000)
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- igbc.cn 版权所有 湘ICP备2023023988号-5
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务