esquivelia
esquivelia

Reputation: 1

Cross Domain communication with iframe - to scroll to top

So I need a button(submit) withing the iframe to trigger the parent page to scroll to the top.

Here is what I have so far:

The iframe..

    $(function () {
     $("searchcrew").bind('click', function (event) {
            window.postMessage("scrollTop","#domain of parent page");
     });
});

The button in the iframe...

    <input id="searchcrew" name='NavAction' type='submit' class="form_1" value='Search'>    </div>

The parent page...

        window.addEventListener("message", receiveMessage, false);

function receiveMessage(event)
{
  if (event.origin !== "#domain of iframe .asp")
    return;

  if (event.data == "scrollTop"){
  window.scrollTo(0,0);
  }
}

Any help would be great! Thanks!

Upvotes: 0

Views: 1091

Answers (1)

BYTE RIDER
BYTE RIDER

Reputation: 169

Looks OK, except you need $("#searchcrew") instead of $("searchcrew").

Upvotes: 1

Related Questions