0

I have two apex pages. First one contains iframe which I'm using to load second page. What I'm trying to do is to scroll to the top of the page by clicking on button placed on my second page. Unfortunately it is not working correctly. My code looks something like this:

<apex:page>
    <h1>First page</h1>
    <apex:iframe src="secondPage"/>
</apex:page>

<apex:page>
    <script type="text/javascript">
        $(document).ready(function(){
            $('[id$=button]').click(function(){
                $('html,body').animate({scrollTop:0}, 'slow');
            });   
        });
    </script>

    <h1>Second page</h1>
    <apex:outputPanel id="content">
        <p>content</p>
    </apex:outputPanel>
    <apex:commandLink id="button" reRender="content" value="Scroll"/>
</apex:page>
  • Have you tried to use a normal html link like <a href="#" onclick="...">? I think there is a conflict in the commandLink that use reRender. – Sergej Utko Aug 25 '16 at 11:55
0

You can't generally manipulate a document in another frame. It's a security risk. Instead, set up a message handler in the parent frame, and use postMessage from the child frame to request the parent to scroll.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.