opt:iframe height auto resize

some website ,the page content is lazy load, the iframe-resizer seems has trouble with them.
This commit is contained in:
Xiao YiFang 2022-09-04 19:03:27 +08:00
parent 19378d2f83
commit 6e74c27ea2
4 changed files with 18 additions and 4 deletions

View file

@ -46,9 +46,9 @@ void IframeSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
QString baseTagHtml = "<base href=\"" + base + "\">";
QString depressionFocus =
QStringLiteral( "<script type=\"application/javascript\">HTMLElement.prototype.focus=function(){console.log(\".focus has been depressed \");}</script>"
"<script type=\"text/javascript\" src=\"qrc:///scripts/iframeResizer.contentWindow.min.js\"></script>");
QString depressionFocus ="<script type=\"application/javascript\"> HTMLElement.prototype.focus=function(){console.log(\"focus() has been disabled.\");}</script>"
"<script type=\"text/javascript\" src=\"qrc:///scripts/iframeResizer.contentWindow.min.js\"></script>"
"<script type=\"text/javascript\" src=\"qrc:///scripts/iframe-defer.js\"></script>";
// remove existed base tag
articleString.remove( baseTag ) ;

View file

@ -5,5 +5,6 @@
<file>scripts/gd-builtin.js</file>
<file>scripts/gd-custom.js</file>
<file>scripts/jquery-3.6.0.slim.min.js</file>
<file>scripts/iframe-defer.js</file>
</qresource>
</RCC>

View file

@ -49,7 +49,7 @@
});
//monitor iframe height.
$('iframe').iFrameResize({ checkOrigin:false,maxHeight :800,scrolling:true,warningTimeout:0,minHeight :250,log:true});
$('iframe').iFrameResize({ checkOrigin:false,maxHeight :800,scrolling:true,warningTimeout:0,minHeight :250,log:true,autoResize:false});
});
})($_$);

13
scripts/iframe-defer.js Normal file
View file

@ -0,0 +1,13 @@
setInterval(function () {
//in some cases ,the website in iframe will load result after document has been loaded. the height will continue to change.
const body = document.body;
const html = document.documentElement;
const height = Math.max(body.scrollHeight, body.offsetHeight,
html.clientHeight, html.scrollHeight, html.offsetHeight);
if ('parentIFrame' in window) {
console.log("iframe set height to " + height);
parentIFrame.size(height);
}
}, 500);