0

I have a certain page which holds a iframe and gets submitted and then a new message is shown within the iframe, this is a lot shorter then the iframe before so it doesn't go to the point I want it on the page.

Now I want to scroll to the new id using jQuery meaning the user can read it from the top and not have to scroll.

My id of my iframe is "#iframe-container".

if (window.location.pathname.split('/')[1] == "Test.aspx")
    {
        // jquery here.
    }

thanks

mohamed-ibrahim
  • 10,837
  • 4
  • 39
  • 51
user4058171
  • 213
  • 1
  • 4
  • 9

2 Answers2

4
$("html, body").animate({ scrollTop: $('#iframe-container').offset().top }, 1000);

You can change 1000 to be less to scroll faster or even to 0 to jump to the ID directly.

$("html, body").animate({ scrollTop: $('#iframe-container').offset().top }, 0);
mohamed-ibrahim
  • 10,837
  • 4
  • 39
  • 51
-2

Cross-window post message API support to communicate to new domain . using post message method.

 In iframe page

     iframe.contentWindow.postMessage("your message",iframe.src);

    source page:



    if (window.addEventListener) {
            window.addEventListener('message', function (e) {
                 if(e.data =="yourmess age"){
                          $(window.parent.document).scrollTop();
                        }
J.M.Farook
  • 183
  • 1
  • 8