【问题标题】:Cross Domain communication with iframe - to scroll to top使用 iframe 进行跨域通信 - 滚动到顶部
【发布时间】:2014-05-07 02:59:42
【问题描述】:

所以我需要一个带有 iframe 的按钮(提交)来触发父页面滚动到顶部。

这是我目前所拥有的:

iframe..

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

iframe 中的按钮...

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

父页面...

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

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

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

任何帮助都会很棒!谢谢!

【问题讨论】:

    标签: iframe cross-domain postmessage


    【解决方案1】:

    看起来不错,只是你需要 $("#searchcrew") 而不是 $("searchcrew")。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-14
      • 2023-03-12
      • 2014-02-16
      • 1970-01-01
      • 2017-08-13
      • 2013-04-01
      • 2021-07-14
      相关资源
      最近更新 更多