您好,欢迎来到爱够旅游网。
搜索
您的当前位置:首页Electron常用api之webview

Electron常用api之webview

来源:爱够旅游网

Electron提供了webview标签,用来嵌入Web页面。

它作用上类似于HTML里的iframe标签,但跑在进程中,主要出于安全性考虑。它不拥有渲染进程的权限,并且应用和嵌入内容之间的交互全部都是异步的.因为这能保证应用的安全性不受嵌入内容的影响。

开启webview

main.js

        webPreferences: {
            webviewTag: true, // 开启webview
        }

常用属性:

preload

在其他脚本执行之前预加载一个指定的脚本。

渲染进程:

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)

常用方法:

insertCSS(css):

  • css String

executeJavaScript(code, userGesture, callback):

  • code String
  • userGesture Boolean - 默认 false.
  • callback Function (可选) - 回调函数.
  • result 评估 code ,如果 userGesture 值为 true ,它将在这个page里面创建用户手势. HTML APIs ,如 requestFullScreen,它需要用户响应,那么将自动通过这个参数优化.

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- igbc.cn 版权所有 湘ICP备2023023988号-5

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务