我在Tomcat中托管的同一个应用程序中有两个HTML页面。在一个HTML页面中有一个iFrame
。我需要通过此iFrame加载其他HTML页面。
下面我提到了 controller.html
<html lang="en">
<head>
<meta charset="utf-8">
<title>postMessage Demo: Controller</title>
</head>
<body>
<h1>Controller Window</h1>
<p>
This document is on the domain: http://codepen.io
</p>
<p>
<button id="send">Send Message</button>
</p>
<iframe id="receiver" src="http://localhost:8080/playground/receiver.html" width="400" height="200">
<p>Your browser does not support iframes.</p>
</iframe>
<script>
var btn=document.getElementById("send");
btn.onclick = function () {
alert("tedt")
receiver.contentWindow.postMessage("hi", "*");
alert("oop")
}
</script>
</body>
</html>
receiver.html
<html lang="en">
<head>
<meta charset="utf-8">
<title>postMessage Demo: Receiver</title>
</head>
<body>
<h1>Receiver Window</h1>
<p>
This document is on the domain: http://demos.matt-west.com
</p>
<div id="message"></div>
<script>
message.onload = function () {
alert('It works!');
var mm=document.getElementById("message");
mm.innerHTML="asasasas";
}</script>
</body>
</html>
当接收者收到请求时,它应该显示警告'It works'但它没有显示。请帮我解决这个问题。
由于
答案 0 :(得分:0)
Google使用 X-FRAME-OPTIONS HTTP 标头禁止将其网页放入iframe:https://developer.mozilla.org/en/The_X-FRAME-OPTIONS_response_header
几乎所有现代浏览器都拒绝将带有此HTTP标头的网页放在iframe中。你无能为力。