Scrolling a page to the top from an iframe (containing a gwt application)

前端 未结 4 2107
北恋
北恋 2021-01-25 23:42

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

4条回答
  •  太阳男子
    2021-01-26 00:08

    How about using JSNI and scrolling in parent or top window? Something like this:

    public static native void scrollToTop()  /*-{
        $wnd.parent.scrollTo(0,0);  // or `$wnd.top.scrollTo(0,0);
    }-*/;
    

    The combination with top should also work with just "window". The $wnd is just because GWT is actually running in an embedded iframe. But I'm not sure if your code will be allowed to scroll parent document if they come from different servers.

提交回复
热议问题