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

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

问题描述

有一个网站,其中包含一个网页应用程序的iframe。我们假设该应用程序的高度为1000px。在应用程序的底部(1000px)有按钮。如果用户按下按钮,那么应用程序将更改其视图,新的长度仅为20px(因此,20px到1000px的范围因此只是白色(空白页))。



我的目标是现在当有人按下该按钮时,浏览器应该将其页面滚动到顶部(这意味着滚动发生在iframe之外。是否有人知道如何在gwt中执行此操作的解决方案(不需要在页面持有iframe)?



很多thx提前!

解决方案

最后,我找到了解决方案,在iframe的顶部设置一个锚点并将其调用:

  public static native void scrollToTop ()/ *  -  {

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

} - * /;



这也会强制父窗口(持有iframe的窗口)滚动到该锚。


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) ).

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)?

Many thx in advance!

解决方案

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';

}-*/;

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

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

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