。
iFrameに含まれるページは、postMessageを使用して現在の高さを含むページに送信する必要があります。 インクルードするページはそのメッセージをリッスンし、それに応じてiframeの高さを変更する必要があります。
含まれるページ内のコードは次のようになります:
function getBottom() {
var max = jQuery("body").height();
//Your additional calculations go here
return max;
}
function updateHeight() {
sendHeightToParent();
setTimeout(updateHeight, 500);
}
function sendHeightToParent() {
var messageObject = {
"type":"size",
"version":"1.0.0",
"params":{
"height": getBottom()
}
};
//YOURTARGET is the target page if known. Otherwise use "*"
parent.postMessage(JSON.stringify(messageObject), "YOURTARGET");
}
//Only possible if html5 post message is available
if (typeof parent.postMessage == 'function') {
jQuery().ready(function() {
sendHeightToParent();
setTimeout(updateHeight, 500);
});
}
親が、イベントをリッスンし、それに応じIFRAMEを更新します。
bodyタグから
//Only possible if html5 post message is available
if (typeof parent.postMessage == 'function') {
window.addEventListener("message", function (e) {
obj = JSON.parse(e.data);
if (obj.type == 'size') {
myFrame = document.getElementById('YouIFrameId');
myFrame.stye.height = obj.params.height + "px";
}
}
}
私がする必要がある方法iframeから呼び出しを呼び出す必要があります。 – user386430
iframeを含むページで、2番目のコードを追加します。 付属のページに、最初のコードを追加します。 –
。index.jspの同じページにiframeを追加しました。 – user386430