我有一个基本的iframe嵌入HTML内容。我应用了一个解决方法,让它在IE11中工作,但在Edge中不起作用。在Chrome和FireFox中工作得很好。我一半的用户都在边缘..。
<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>边缘只显示一个空白,错误出现在JS上
SCRIPT5007: SCRIPT5007: Unable to get property 'getAttribute' of undefined or null reference
javascript: window.frameElement.getAttribute('srcdoc'); (1,2)发布于 2019-03-26 05:22:08
看起来window.frameElement是空的,因此它无法使用getAttribute获得“srcdoc”。
下面可能是“空”的原因。
如果窗口没有嵌入到另一个文档中,或者它嵌入到的文档有不同的来源(例如位于不同的域),则此值为null。
因此,您可以尝试检查上面提到的条件,我建议您创建一个脚本段,并尝试检查window.frameElement是否为空。如果它不是null,请尝试使用GetAttribute,然后将其值赋值给IFrame src。
另外,您需要注意的是,MS中不支持srcdoc属性。因此,Edge将不会对该属性产生任何影响。
参考文献:
https://stackoverflow.com/questions/55345838
复制相似问题