【问题标题】:Using NavigationHandler.handleNavigation doesn't show the top of the page使用 NavigationHandler.handleNavigation 不显示页面顶部
【发布时间】:2016-12-11 21:51:06
【问题描述】:

我正在使用此处建议的 NavigationHandler.handleNavigation (ExternalContext.dispatch() not working),因为我使用的是 ajax 请求。

它有效,但我在页面中间看到下一页(或多或少),而不是在页面顶部看到它。

我尝试使用此处建议的锚 (http://www.computerhope.com/issues/ch001475.htm),但它也不起作用。

知道发生了什么吗?

这是我的代码:

context.getApplication().getNavigationHandler().handleNavigation(context, null, "/user-registration.xhtml#top");

我在下一页正文的开头添加了以下内容:

<a name="top"></a>

【问题讨论】:

    标签: ajax jsf navigation


    【解决方案1】:

    将窗口滚动到顶部的正确方法是window.scrollTo()xy0

    window.scrollTo(0, 0);
    

    这使您的 URL 没有散列碎片。

    为了在每个 JSF ajax 事件成功时调用它,请在文档中包含以下脚本。

    jsf.ajax.addOnEvent(function(data) {
        if (data.status == "success") {
            window.scrollTo(0, 0);
        }
    });
    

    另见:

    【讨论】:

      【解决方案2】:

      最后我用下面的脚本解决了:

      <script type="text/javascript">
        $(document).ready(function() {
          location.hash = "#top";
        });
      </script>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-11-12
        • 1970-01-01
        • 1970-01-01
        • 2016-10-20
        • 2014-08-09
        • 2018-04-30
        • 1970-01-01
        相关资源
        最近更新 更多