From 376f0f1c6260d42463868a558511c5b4c537d9cf Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Sun, 17 Apr 2022 22:28:14 +0800 Subject: [PATCH] fix: qt6.2 iframe can not access gdlookup built-in javascript it throw CORS exception in the devtool console windows. --- resources/gd-custom.js | 35 ++++++++++++++++++++++------------- website.cc | 2 +- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/resources/gd-custom.js b/resources/gd-custom.js index ae5bba3b0..ae07cf319 100644 --- a/resources/gd-custom.js +++ b/resources/gd-custom.js @@ -44,6 +44,27 @@ $(function() { }); + //monitor iframe height. + + $( "iframe" ).on( "load", function() { + var iframe = $( this ); + resizeIframe( iframe[ 0 ] ); + } ); + + function resizeIframe(obj) { + setInterval(function(){ + //in some cases ,the website in iframe will load result after document has been loaded. the height will continue to change. + if($(obj).contents().height() <2000) + { + $(obj).height($(obj).contents().height()); + } + else{ + $(obj).height(2000); + obj.scrolling="yes"; + } + },500); + } + }); })($_$); @@ -52,16 +73,4 @@ function playSound(sound) { a.play(); } -function resizeIframe(obj) { - setInterval(function(){ - //in some cases ,the website in iframe will load result after document has been loaded. the height will continue to change. - if(obj.contentWindow.document.documentElement.scrollHeight <1000) - { - obj.style.height = obj.contentWindow.document.documentElement.scrollHeight + 'px'; - } - else{ - obj.style.height ='1000px' - obj.scrolling="yes"; - } - },500); -} + diff --git a/website.cc b/website.cc index 39b1adce4..d7048cc01 100644 --- a/website.cc +++ b/website.cc @@ -376,7 +376,7 @@ sptr< DataRequest > WebSiteDictionary::getArticle( wstring const & str, "\" onmouseover=\"processIframeMouseOver('gdexpandframe-" + getId() + "');\" " "onmouseout=\"processIframeMouseOut();\" " "scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" " - "frameborder=\"0\" vspace=\"0\" hspace=\"0\" onload=\"resizeIframe(this)\"" + "frameborder=\"0\" vspace=\"0\" hspace=\"0\"" "style=\"overflow:visible; width:100%; display:block;\">" "";