iframe -
问题描述
I have a basic iframe embedding HTML content. I applied a workaround to get it to work in IE11, but doesn't work in Edge. Works great in Chrome and FireFox. Half of my users are on 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 just shows a blank space, errors out about the JS
SCRIPT5007: SCRIPT5007: Unable to get property 'getAttribute' of undefined or null reference
javascript: window.frameElement.getAttribute('srcdoc'); (1,2)
解决方案
看起来window.frameElement为 NULL,因此无法使用getAttribute获取 'srcdoc' 。
以下可能是它为 Null 的可能原因。
如果窗口没有嵌入到另一个文档中,或者如果嵌入它的文档具有不同的来源(例如来自不同的域),则此值为 null。
因此,您可以尝试检查上述标准,我建议您创建一个脚本段并尝试检查window.frameElement是否为 Null。如果它不为空,则在将其值分配给 IFrame src 之前尝试使用GetAttribute 。
您需要注意的另一件事是 MS Edge 不支持srcdoc属性。所以 MS Edge 不会对该属性产生任何影响。
参考:
推荐阅读
- python - python strftime 应用时区或添加 3 小时
- javascript - 无法从 mysql 获取 Vuejs 中的 DD-MM-YYYY 日期格式
- c - 编译 GCC Ubuntu 时出错:未定义的引用
- reactjs - 问题:下面的代码在开发中完美地工作,但在上传到 Heroku 后它有时可以工作,
- c# - 在 ASP.NetCore 3.1 MVC 中通过考试后将分数设置到数据库
- java - 具有多个线程的 SecureRandom 流奇怪行为
- ibm-cloud - IBM Cloud Schematics:如何将运行时从 Terraform v0.12 升级到 v0.13?
- android - 当我从 qr_code_scanner 包打开 QRView 小部件时出现平台异常
- dart - 如何在 dart 中创建一个空的类型列表
- python - KIVY python 虚拟键盘