[英]Using HTML import to load entire HTML page inside a DIV
我们有一个 HTML 页面,它充当多个应用程序的网关。 该网站有几个按钮和一个 IFRAME。 单击按钮后,我们会在 IFRMAE 中加载其他 HTML 页面。 所有这一切都很好。 但是我们希望在支持 IE 11 的同时利用 HTML 导入/Web 组件来实现相同的目的。 我想本地化我们正在导入的这个 HTML 页面的 scope,这样它就不会干扰现有的应用程序。
我们怎样才能做到这一点? 这种方法有什么缺点吗。
这是我们目前所拥有的。
索引.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title>Test</title>
<script src="https://code.jquery.com/jquery-3.5.0.min.js"
integrity="sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=" crossorigin="anonymous"></script>
<script>
$(document).ready(function () {
$("#btnAbout").click(function () {
document.getElementById('iframe').src = "about.html";
});
$("#btnContact").click(function () { $("#iframe").attr("src", "contact.html") });
$("#btnApple").click(function () {
document.getElementById('iframe').src = "https://www.Apple.com/";
});
});
</script>
<style>
body {
height: 96vh;
padding: 0;
}
</style>
</head>
<body style="border: 1px;border-style: dashed; color: brown;">
<div>
<input type="button" value="Yahoo" id="btnAbout" />
<input type="button" value="MS" id="btnContact" />
<input type="button" value="Apple" id="btnApple" />
</div>
<iframe id="iframe" width="100%" height="96%"></iframe>
</body>
</html>
关于.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title> About</title>
</head>
<body>
<div style="border-style: dotted; color: crimson; height: 1000px;">
this is a div
</div>
</body>
</html>
用户.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
</head>
<body>
<div>
user page
</div>
</body>
</html>
联系方式。html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
</head>
<body>
<div>
this is content page
</div>
</body>
</html>
最大的缺点是大多数主流浏览器不再支持 HTML 导入。
来源: https://developer.mozilla.org/en-US/docs/Web/Web_Components/HTML_Imports
替代和支持的解决方案如下:
以上所有内容都可以在 IE11 上正常工作,尽管我会完全放弃对 IE11 的支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.