【问题标题】:Electron APP shows undefined document.bodyElectron APP显示未定义的document.body
【发布时间】:2018-12-06 02:36:50
【问题描述】:

您好,我正在使用电子加载外部 URL,在外部 URL 中,我有下面的脚本显示 window.open 内的 iframe。

var myWindow = window.open("", "_blank", "width=600,height=400");
myWindow.document.body.innerHTML = "<iframe allowFullScreen='true'></iframe>";

在普通浏览器中它工作正常,但在电子应用程序中我收到以下错误:

未捕获的类型错误:无法读取未定义的属性“正文”

欢迎提出任何建议。

【问题讨论】:

    标签: javascript electron


    【解决方案1】:

    根据 Electron 文档,window.open 返回一个 BrowserWindowProxy 对象:

    类:BrowserWindowProxy

    进程:渲染器

    BrowserWindowProxy 对象是从 window.open 返回的,并且 为子窗口提供有限的功能。

    代替:

    myWindow.document.body.innerHTML = "<iframe allowFullScreen='true'></iframe>";
    

    你可以试试:

    myWindow.eval (`document.body.innerHTML = "<iframe allowFullScreen='true'></iframe>";`);
    

    请注意这里使用反引号字符串表示法以避免必须同时转义单引号和双引号,但这绝对是一个品味问题......

    HTH...

    【讨论】:

      猜你喜欢
      • 2016-03-17
      • 2015-12-13
      • 2017-11-11
      • 1970-01-01
      • 2017-08-11
      • 1970-01-01
      • 2019-01-28
      • 1970-01-01
      相关资源
      最近更新 更多