tltoulson
Kilo Sage

Update (03/21/2017): This script currently only works if the Frame Name on your iFrame is gsft_main.   Thanks to Anil Varanasi for catching this!

36 Comments
tltoulson
Kilo Sage

Hi Dinesh,



I would have to take a closer look at the specific code that you are using on your site.   The most likely cause of the issue you are seeing is that the height of the measured divs within the iFrame is changing.   This iFrame resize script only changes the height of the frame if the height of the contents changes.   So I would need to take a closer look at the HTML, CSS, and JS of the contents of the iframe to see why the height is jittering.


renakhanna
Kilo Contributor

Hi Travis


Thanks For Your Reply


                                                                                                        I Deleted Below Script In Iframes.When I Deleted Below Script Problem Was Resolved.But I Dont No How It's Work.




(function() {


var contentWindow = '',


iframeArray = [],


pollingDelay = 250,


prevHeight,


src = '',


blacklist = [],


bottomMargin = 30;




/**


  * Executes the proper calculation strategy and returns the internal height of the iframe.   You should edit this function if you find strategies that are not accounted for


  * @function getHeight


  */


var getHeight = function() {


if (contentWindow.$j('body')[0].style.overflow != 'hidden') {


contentWindow.$j('body')[0].style.overflow = 'hidden';


}


//if (iframePageIs('$knowledge.do') || iframePageIs('knowledge_home_launcher.do')) {


if (iframePageIs('$knowledge.do')) {


// Knowledge v3 UI


// Shrink iframe when the src changes to force a recalculation


if (src != contentWindow.location.href) {


src = contentWindow.location.href;


return 700;


}




return getTotalHeight(['.application'], 0);


}


else if (iframePageIs('kb_view.do')) {


return getTotalHeight([


'body > .outputmsg_div',


'body > .navbar',


'.kb-view-content-wrapper',


'.snc-article-header-author',


'.snc-article-footer-section',


'.snc-article-footer'


], 0);


}


else if (iframePageIs('kb_home.do')) {


return getTotalHeight([


'body .navbar',


'body > .kb_main'


], bottomMargin);


}


else


return null;


};




/**


  * @function getTotalHeight


  * @param {array} divs - Array of CSS selectors that identify the div's whose height should be added in the calculation


  * @param {int} modifier - Number of additional pixels to add as a modifier


  */


var getTotalHeight = function(divs, modifier) {


var h = 0;




$j.each(divs, function(ix, val) {


h = h + contentWindow.$j(val).height();


});




return h + modifier;


};




/**


  * Determines if the url contains the given fragment


  * @function iframePageIs


  * @param {string} urlFragment - String to search for in the iframe url


  *


  */


var iframePageIs = function (urlFragment) {


return (contentWindow.location.href.indexOf(urlFragment) != -1);


};




/**


  * A recursive polling function that gets the internal height of the iframe and resizes the it accordingly.


  * @function resizeIframeFix


  */


var resizeIframeFix = function(iframe) {


setTimeout(function() {


var curHeight;


var i;




for (i = 0; i < blacklist.length; i++) {


if (iframePageIs(blacklist[i])) {


return;


}


}




if ($j && contentWindow.$j) {


curHeight = getHeight();




if (curHeight !== null && prevHeight != curHeight) {


$j(iframe).height(curHeight);


prevHeight = getHeight();


}


}




resizeIframeFix(iframe);


}, pollingDelay);


};




// Initiate knowledge page resize if we are in iframe and not in platform UI iframe


if (top != window && top.location.pathname != '/navpage.do' && top.location.pathname != '/nav_to.do') {


//detect end of page - scrolling


$j(top).scroll(function() {


if(top && typeof angular !== 'undefined'){


if($j(top).scrollTop() + $j(top).height() == $j(top.document).height()) {


var articleScope = angular.element($j('div[articles-container]')[0]).scope(),


searchScope = angular.element($j('.search-results')[0]).scope();




if(articleScope)


articleScope.$parent.$parent.getArticlesAndQuestions();


if(searchScope)


searchScope.$parent.$parent.executeSearch(searchScope.filterQuery.keywords);


}


}


});


//resizing


parent.addAfterPageLoadedEvent(function() {


contentWindow = window; //iframe window


resizeIframeFix(parent.window.$j('iframe'));


});


}


})();



Thanks


Dinesh


Ben Collyer
Giga Guru

Nice piece of work!



For Wizards (if anyone still uses these) add and if else block like this:



else if (iframePageIs('expert_shell.do')){
//Wizards
return getTotalHeight([
'body'
], 200);
}


tltoulson
Kilo Sage

Thanks Ben!   I have added your changes to the Gist and can confirm that it works without issue.


jperoz
Mega Explorer

Hi Travis,



We are testing Jakarta and the global search returns a cut off page with two scroll bars. I have tried to implement your code above, but it has know effect. The search results page returned is called main_content.do, so I added this to your script. It still doesn't work. We are still using CMS.



find_real_file.png


tltoulson
Kilo Sage

Hi James,



Sorry to hear it's not working out for you.   It sounds like you've got some customizations as the out of box CMS does not have a main_content.do page.   I think we can get this script to work for you by adding a configuration specifically for main_content.do in the script but we'll have to determine which HTML divs make up the height of the page.   It will probably be easiest if we can work together over a screen share / call.   Shoot me an email @ tltoulson@gmail.com if you want to arrange.



At the very least, explaining how to determine the correct configuration will be easier on a call than typing it out!   😄