electron的webview中注入js-back

2020-07-28  本文已影响0人  苏本的书柜

将文件读取到字符串并执行它

//myApp.isPacked 用来判断是否是打包,打包之后路径引入需要更改


import path from 'path'
import fs from 'fs'
this.webview.addEventListener('dom-ready', () => {
                    const filePath = myApp.isPacked ? path.resolve('static/js/webview/html.js') : 'static/js/webview/html.js'
                    const js = fs.readFileSync(filePath).toString();
                    this.webview.executeJavaScript(js);
                })
上一篇 下一篇

猜你喜欢

热点阅读