【问题标题】:<iframe not working in Edge, but works in Internet Explorer 11<iframe 在 Edge 中不工作,但在 Internet Explorer 11 中工作
【发布时间】:2019-03-25 20:22:50
【问题描述】:

我有一个嵌入 HTML 内容的基本 iframe。我应用了一种解决方法让它在 IE11 中工作,但在 Edge 中不起作用。在 Chrome 和 FireFox 中运行良好。我有一半的用户在 Edge...

<iframe
    title="My iframe should work"
    class="large"
    id="my-slide-should-work"
    src="javascript: window.frameElement.getAttribute('srcdoc');" // this fixed it for IE11
    scrolling="no"
    srcdoc='<!DOCTYPE html><html>all the goodness</html>'>
</iframe>

Edge 只显示一个空格,关于 JS 的错误提示

SCRIPT5007: SCRIPT5007: Unable to get property 'getAttribute' of undefined or null reference
javascript: window.frameElement.getAttribute('srcdoc'); (1,2)

【问题讨论】:

    标签: iframe microsoft-edge


    【解决方案1】:

    看起来 window.frameElement 为 NULL,因此无法使用 getAttribute 获取“srcdoc”。

    以下可能是它为 Null 的可能原因。

    如果窗口没有嵌入到另一个文档中,或者如果该文档 它嵌入的地方有不同的起源(例如 位于不同的域),这是 null。

    所以您可以尝试检查上述条件,我建议您创建一个脚本段并尝试检查 window.frameElement 是否为 Null。如果它不为空,则在将其值分配给 IFrame src 之前尝试使用 GetAttribute

    您需要注意的另一件事是,MS Edge 不支持 srcdoc 属性。所以 MS Edge 不会对该属性产生任何影响。

    参考资料:

    (1)Window.frameElement

    (2)<'iframe'>: The Inline Frame element

    【讨论】:

      猜你喜欢
      • 2015-11-06
      • 2015-09-13
      • 1970-01-01
      • 2016-03-04
      • 2013-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多