Html iFrame 内容不显示在 IE8 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11191155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:15:28  来源:igfitidea点击:

iFrame content doesn't show in IE8

htmliframeinternet-explorer-8cross-browser

提问by strah

I have a site with an iFrame.

我有一个带有 iFrame 的网站。

The host page has some very basic JS on it, the iframed page has simple JS too.

主机页面上有一些非常基本的 JS,iframe 页面也有简单的 JS。

When I embed the iframe as usualy: <iframe src="iframeURL" width="900" height="1000"></iframe>it works fine in all browsers but IE8.

当我像往常一样嵌入 iframe 时:<iframe src="iframeURL" width="900" height="1000"></iframe>它在除 IE8 之外的所有浏览器中都能正常工作。

I tried various things:

我尝试了各种事情:

  • first: disabling all JS
  • removing src attribute and adding it with JS
  • using <object>instead
  • I used proxy.php to make the content appear as if it were coming from the same domain
  • 第一:禁用所有JS
  • 删除 src 属性并使用 JS 添加它
  • 使用<object>替代
  • 我使用 proxy.php 使内容看起来好像来自同一个域

It doesn't work in IE8 regardless what I do.

不管我做什么,它在 IE8 中都不起作用。

The funny thing is that I can open the page I want to iframe in a separate tab and works just fine.

有趣的是,我可以在单独的选项卡中打开我想要 iframe 的页面并且工作正常。

If I change the src attribute to "some_other_random_page_from_internet" it works.

如果我将 src 属性更改为“some_other_random_page_from_internet”,它会起作用。

The other thing is that both host and iframe use postMessage to communicate and I can see the communication is working OK, it's just the content which doesn't show, but when I inspect the page source with developers tools I can see the content is there.

另一件事是主机和 iframe 都使用 postMessage 进行通信,我可以看到通信工作正常,只是没有显示内容,但是当我使用开发人员工具检查页面源时,我可以看到内容在那里.

Is it possible that the content of the iframe causes issues? It's a basic HTML + basic JS, with JS disabled it shouldn't be an issue.

iframe 的内容是否有可能导致问题?这是一个基本的 HTML + 基本 JS,禁用 JS 应该不是问题。

Any ideas what else I could check?

任何想法我还能检查什么?

PS. I can't show the code (NDA , etc)

附注。我无法显示代码(保密协议等)

回答by strah

Found it.

找到了。

The iframed content had the following css rule:

iframe 内容具有以下 css 规则:

html{ position: relative; }

Removing it helped a lot.

删除它有很大帮助。

回答by KyleMit

For visibility of Lukx's comment, the real answer is to set position:relativeon the iframe itself, since you might not have the ability to edit the html source page or it might need to use relative positioning.

对于Lukx 评论的可见性,真正的答案是position:relative在 iframe 本身上进行设置,因为您可能无法编辑 html 源页面或者它可能需要使用相对定位。

Just add this CSS and you should be all set:

只需添加这个 CSS,你就应该准备好了:

iframe {
    position: relative;
}

I wrote up a full description of the problem in this answer

我在这个答案中写了一个完整的问题描述