Support Article
Javascript scroll to bottom not working in IAC
SA-24674
Summary
We have a requirement in a question and answer flow to scroll to the bottom each time an assignment screen loads. This is so the last question is visible to the user and new questions are added each time the user submits a screen.
We added the following Javascript and it works fine when testing in standard end user desktop. It is not working when testing the flow in IAC.
<script>
window.scroll(0,50000000);
window.onload=toBottom;
function toBottom()
{
window.scrollTo(0, document.body.scrollHeight);
}
</script>
Error Messages
Not Applicable
Steps to Reproduce
Standard Web Mashup using createNewWork.
Root Cause
When imbedding the gadget the scroll bars were part of the top level application and not within PRPC. The gadget HTML was within a top level application iframe so to auto scroll to the bottom onload of the PRPC content the top level application has to handle this.
Resolution
In PRPC when you want to tell the parent application to scroll to bottom send a message through the IAC custom event to the parent applicaiton.
Put the following in section in the harness were you want to tell the top level application to scroll to bottom on the onload event of the PRPC content.
<script>
window.onload=toBottom;
function toBottom(){
pega.desktop.gadgetCustomEvent("ScrollToBottom");
}
</script>
In the top level application gadget HTML:
function pegaCustom(gadgetName,strToken) {
if (strToken == "ScrollToBottom") {
scrollToBottomOfParentIframe();
}
}
function scrollToBottomOfParentIframe(){
var parentIframe = TODO: Top Level Application Developer: Find parent iframe window object.
parentIframe.scrollTo(0, parentIframe.document.body.scrollHeight);
}
Published June 20, 2016 - Updated October 8, 2020
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.