从 iframe 将页面滚动到顶部(包含 gwt 应用程序) [英] Scrolling a page to the top from an iframe (containing a gwt application)

查看:33
本文介绍了从 iframe 将页面滚动到顶部(包含 gwt 应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个网站有一个包含网络应用程序的 iframe.假设应用程序的高度为 1000 像素.在应用程序的底部(1000px)有按钮.如果用户按下按钮,那么应用程序会改变它的视图,并且新的长度只有 20px(从 20px 到 1000px 的范围因此只是白色(空白页)).

There is a website which has an iframe including a web application. Let's assume that the application has a height of 1000px. At the bottom of the application (1000px) there is button. If the user presses the button, then the application changes its view and the new length is only 20px (the rage 20px to 1000px is therefore just white (blank page) ).

我现在的目标是,当有人按下该按钮时,浏览器应将其页面滚动到顶部(这意味着滚动发生在 iframe 之外.有谁知道如何在 gwt 中做到这一点的解决方案(不设置锚点)在包含 iframe 的页面中)?

My goal is now that when someone presses on that button then the browser should scroll its page to the top (meaning that the scrolling happens outside the iframe. Does anyone know a solution how to do that in gwt (without setting an anchor in the page holding the iframe)?

提前多谢!

推荐答案

终于找到了解决方案.在你的 iframe 顶部设置一个锚点并调用它:

Finally I found the solution. Set at the top of your iframe an anchor and call it with:

public static native void scrollToTop()  /*-{

    $wnd.location.href = '#anchorName';

}-*/;

这也将强制父窗口(持有 iframe 的窗口)滚动到该锚点.

This will also force the parent window (the window holding the iframe) to scroll to that anchor.

这篇关于从 iframe 将页面滚动到顶部(包含 gwt 应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆