iframe adaptive height itself is a very simple method, which is to recalculate the height after the page is loaded.
The code is as follows:
//Public method: Setting The height of the iframe to ensure that all data is displayed
//function SetPageHeight() {
// var iframe = getUrlParam('ifname');
// var myiframe = window.parent.document.getElementById(iframe );
// iframeLoaded(myiframe);
//}
var iframeLoaded = function (iframe) {
if (iframe.src.length > 0) {
if (! iframe.readyState || iframe.readyState == "complete") {
var bHeight =
iframe.contentWindow.document.body.scrollHeight;
var dHeight =
iframe.content Window.document.documentElement .scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
}
}
}
//Reset the iframe height when paginating ; After modification: iframe.name = iframe.id
var reSetIframeHeight = function()
{
try {
var oIframe = parent.document.getElementById(window.name);
oIframe .height = 100; 00 ;
} catch (err2) { ;
But there is another situation where jquery ajax is used to request data. After the body load is completed, the data is still making an http request. At this time, there is no data occupying the window height, and the reSetIframeHeight method cannot calculate the height.
At this time, we think of a method: when can ajax be executed? Of course, the Complete event is when the execution is completed.
But we cannot add processing to the ajax Complete event in each page. The global variables of jquery ajax are used here.
Code to handle ajax and iframe adaptation:
Copy code
The code is as follows:
var sendcount = 0;
var completecount = 0;
}).ajaxComplete(function (e, xhr, opts) {
completecount ;
reSetIframeHeight();
}).ajaxStop(function () {
});
Execute reSetIframeHeight first, and then after each ajax is completed Call reSetIframeHeight.
Tested and valid.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn