修改创建BrowserWindow部分的相关代码,设置属性webPreferences.nodeIntegration为 true
let win = new BrowserWindow({ webPreferences: { nodeIntegration: true } })参考: https://www.cnblogs.com/kuku19940613/p/10814905.html
嗯 主界面的这个错误解决了 然而 嵌套的iframe 里面又报这个错误。 这每个页面都要来这么一下么?
这是找遍了各种 google 百度都没能解决我的问题 最典型的是以下的解决方案 这里也列出来 说不定能解决你们的问题呢?
// 在主进程中 const { BrowserWindow } = require('electron') let win = new BrowserWindow({ webPreferences: { nodeIntegration: false } }) win.show()Copy假如你依然需要使用 Node.js 和 Electron 提供的 API,你需要在引入那些库之前将这些变量重命名,比如:<head>
<script> window.nodeRequire = require; delete window.require; delete window.exports; delete window.module; </script> <script type="text/javascript" src="jquery.js"></script> </head>以上方法都用了 然鹅依然没有解决我的问题最终在这里找到了我的解决方案参考: https://stackoverflow.com/questions/45255773/electron-iframe-require-is-not-defined
iframe.onload = function () { const iframeWin = iframe.contentWindow iframeWin.require = window.require })也就是在我的工程中在主进程中 // 在主进程中 const { BrowserWindow } = require('electron') let win = new BrowserWindow({ webPreferences: { nodeIntegration: true } }) win.show()在iframe嵌套的地方
var node_frame = document.createElement("iframe"); node_frame.onload = function () { node_frame.contentWindow.require = window.require };
转载于:https://www.cnblogs.com/lesten/p/11602083.html
相关资源:JAVA上百实例源码以及开源项目