마침내 iframe에 대한 교차 도메인 기능이 작동했습니다. 지금 가지고있는 문제는 첫 페이지가 꽤 길다는 것입니다. 작은 페이지로 iframe 내의 링크를 클릭하면 iframe의 크기가 자동으로 조정되지 않고 이전 페이지 높이가 가장 아래쪽에 큰 간격이 생깁니다.자동 크기 조정 iFrame
<!DOCTYPE html>
<head>
</head>
<body onload="parent.postMessage(document.body.scrollHeight, 'http://target.domain.com');">
<h3>Got post?</h3>
<p>Lots of stuff here which will be inside the iframe.</p>
</body>
</html>
코드 iframe을 표시 할 수있는 주요 도메인에 간다 : 외부 도메인에 간다
코드 :
내가 사용하는 코드는 다음과
<script type="text/javascript">
function resizeCrossDomainIframe(id, other_domain) {
var iframe = document.getElementById(id);
window.addEventListener('message', function(event) {
if (event.origin !== other_domain) return; // only accept messages from the specified domain
if (isNaN(event.data)) return; // only accept something which can be parsed as a number
var height = parseInt(event.data) + 32; // add some extra height to avoid scrollbar
iframe.height = height + "px";
}, false);
}
</script>
<iframe src='http://example.com/page_containing_iframe.html' id="my_iframe" onload="resizeCrossDomainIframe('my_iframe', 'http://example.com');">
는 사람이 어떻게를 수정하는 어떤 아이디어를 가지고 있고, 않음 경우 내가 수정해야 할 것을 보여줄 수 있습니까?
감사합니다.
나는 편집하고 모든 나의 생각을 똑바로 얻으 려합니다 ... –
그 도움이 전혀 없었습니까? –
예 ... 기본적으로 기본 페이지 (A)와 동일한 URL로 B의 크기가 포함 된 일종의 해시/매개 변수가있는 iframe (B) 내부에 iframe (C)을 만들고 스크립트 C에서 A에게 어떤 크기 B가 필요한지 알려줍니다. –