- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在正常情况下,具有页面间通信的 Web 应用如果它们的页面是从“http”协议(protocol)中的同一个域提供的,则无需担心跨域访问。默认情况下,Electron 似乎通过"file"协议(protocol)使用网页构建应用程序。该协议(protocol)不允许任何页面间通信。
如果我的 Electron 应用程序需要页面间通信(在这种情况下是通过 iframe),我认为该应用程序需要与 Electron 一起运行网络服务器是正确的吗?这似乎太过分了,我还没有看到太多关于它的讨论,但我看不出有什么更好的解决方法。有一个用于自定义协议(protocol)的 Electron API,但文档没有显示如何使用自定义协议(protocol),只是如何设置它们,我还没有找到任何好的教程。
总的来说,ElectronJS 作为一个框架和一个社区给我留下了深刻的印象,所以我很惊讶在经过一番认真的搜索之后我无法找到解决这个问题的方法。我发现这个问题问了很多次,但没有可靠的答案。我真的很感激一些启示。
更新:
我现在看到我的情况的细节(需要在父窗口和 iframe 之间进行对话)使这个问题比如果有两个单独的窗口(例如主窗口和设置窗口)作为主进程通常可以做的更棘手通过 IPC 充当联络人。这无疑解释了为什么解决方案如此难以捉摸。
最佳答案
我终于找到了解决这个特定问题的方法: Window.postMessage .这是一种 HTML5 技术,允许在跨域的不同窗口之间传递消息,包括 iframe。令人惊讶的是,它适用于"file"协议(protocol)(即没有网络服务器),因此它适用于 Electron 中的 iframe。
这是一个工作示例。我有两个文件:parent.html 和 child.html。前者有一个包含后者的 iframe:
父.html
<html>
<body>
<iframe id='f' src='child.html'></iframe><br/> <!-- First of two differences -->
<button id='b'>send</button><br/>
<div id='o'></div>
</body>
</html>
<script>
function receiveMessage(evt)
{
document.getElementById('o').innerHTML += evt.data + "<br/>";
}
window.addEventListener("message", receiveMessage, false);
document.getElementById('b').onclick = function()
{
// The second of two differences between parent and child is below
document.getElementById('f').contentWindow.postMessage("parent to child", "*");
}
</script>
<html>
<body>
<!-- The first of two differences between parent and child is here -->
<button id='b'>send</button><br/>
<div id='o'></div>
</body>
</html>
<script>
function receiveMessage(evt)
{
document.getElementById('o').innerHTML += evt.data + "<br/>";
}
window.addEventListener("message", receiveMessage, false);
document.getElementById('b').onclick = function()
{
// The second of two differences between parent and child is below
window.parent.postMessage("child to parent", "*");
}
</script>
关于javascript - Electron JS : avoiding cross-origin issues,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58156367/
我正在尝试将网页内容打印到一页纸上。但是,它将内容分成 2 页,所以我在这里做了一些研究,看到有人推荐: #my_print_div{ width:940px; height:770px; page
我目前正在打印一些东西。我有一个动态页面,其中包含可变数量的 block 级元素。有些可能是 1 行,有些可能是 100 多行。 1text 1 line.... 2text 10 lines....
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 9
我正在训练一个 randomForest 模型,目的是保存它以进行预测(它将被下载并在外部上下文中使用)。我希望这个模型尽可能最小。 我读到有很多options和 packages减少模型的内存大小。
这个问题在这里已经有了答案: MySQL connection timeout (3 个答案) 关闭 9 年前。 我一直在尝试使用 Tomcat 的 native 连接池功能来避免我的 Java W
我正在使用 Phonegap/Cordova 开发 Android 应用程序。我已经按照这样的百分比安排了我的布局(在 CSS 中): 标题 - 50px; Content_row1 - 30%(剩下
我正在编写一个插件,它将表情符号转换为特定站点文本 block 中的图像。简单的答案是使用正则表达式检测 innerHTML 上的触发文本并插入 img 标签,然后将字符串通过管道返回到 innerH
如何避免在我的 Drupal View 上重复? 我应该添加一个过滤器,指定特定字段(即用户 ID)不应出现两次吗?我找不到这样的选项 看法 http://dl.dropbox.com/u/72686
感谢您查看我的 typescript 问题。 为简单起见,我对 typescript “过度属性检查”行为有疑问。我想确保 TypeScript 不接受具有额外属性的对象。 在我的简单界面示例中,OF
我发现对于某些图表,我从 Prometheus 获得了 doubles 值,其中应该只是一个: 我使用的查询: increase(signups_count[4m]) 抓取间隔设置为 recommen
假设我正在运行N个线程。 每个线程都需要与下一个和上一个同步。 for (i = 0 ; i < NITER; i++){ do_something (); sync_
如今,服务器虚拟化是一件大事,所以我的任务是在虚拟化服务器上安装我们的一些软件,看看会发生什么。长话短说:rsync 传输会立即使虚拟化服务器崩溃。虚拟化主机是一台强大的机器,没有其他负载;我认为
以下正则表达式在应用于大型 html 页面时会创建 StackOverflowError: (.|\s)*? 我的假设是,这是由于逻辑“OR”运算符(|)在匹配器中创建了递归调用,并且由于需要解析的
我在运行时使用表达式树构建委托(delegate): Type type = GetType(); ParameterExpression parameterType = Expression.Par
我正在使用 scikit-learn TfidfVectorizer 找出两个文档中最重要的单词。每个文档大小为 1.9GB(约 9000 万字),并且已采用小写、词干化(使用 nltk.stem.p
我进行了一个中间件调用来获取 String 数组,如下所示: String[] freqwords = MViewer.getWordNames(); 问题是可能没有可用数据,因此任何进一步的操作(如
在 JavaFx 中,我使用以下代码创建一个 StackedBarChart: String[] ACTIVITIES = new String[10]{ ... };// there
我正在尝试制作一个使用类 AnimationTimer 来处理它的游戏。我的代码摘要如下所示: 主类 object Game extends JFXApp{ def showMenu{
我正在用不同的步骤创建一个小的 javascript/jQuery 应用程序。为此,我使用了一个具有不同功能的 js 文件。 在文件的顶部我调用了我的第一个函数。在我的第一个函数中,我在单击按钮时调用
我正在使用表格 View 来显示从服务器加载的文本字段数组,所以我有一个表格 View 字段列表,当我填充这些数据字段并向下滚动以填充其他字段时,当我再次向上滚动时,我发现值发生变化并且存在重复值 -
我是一名优秀的程序员,十分优秀!