我如何确定我是否要“前进”?或“向后”。通过我在 GWT 中的历史?

发布于 2024-08-29 21:20:35 字数 484 浏览 2 评论 0原文

I am looking at History and History JavaDocs in GWT and I notice that there is no way to tell whether the forward or backward button was pressed (either pragmatically or by the user). The "button press" is handled by your registered addValueChangeHandler, but the only thing passed to the handler is a string on your history stack. There is no indication as to whether the "History" is moving "back" (using the back arrow button) or "forward" (using the right arrow button). Is there any way to determine this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

零度° 2024-09-05 21:20:35

抱歉,你不能。即使可以,有些浏览器(例如 Firefox)可以让用户“跳回”多个页面。因此,如果您尝试依赖相对“坐标”而不是绝对“坐标”,导航可能会破坏您的应用程序。

您始终可以在历史标记上附加某种计数器。如果您只有一个历史监听器,这并不难。

Sorry, you can't. And even if you could, there are browsers, like Firefox, that let the user "jump" back more than one page. So if you try to relying on relative "coordinates" instead of absolute, the navigation could break your app.

You can always append some kind of counter on your history token. It would not be hard, if you have only one history listener.

帅气尐潴 2024-09-05 21:20:35

您可以做的就是拥有一个像这样的 UrlManager:

   public class UrlManager implements ValueChangeHandler<String> {

   public UrlManager() {
     History.addValueChangeHandler(this);       
    }

  public void onValueChange(ValueChangeEvent<String> event) {     
    String historyToken = event.getValue();

  }
   }

将每个历史标记保存到列表中。
如果它是一个全新的历史标记,则将其添加到列表中。
如果是前一个历史标记,则后退按钮已被按下。

我建议使用列表来保存标记并保存一个可以在列表中上下移动的迭代器。所以最初它指向列表的末尾。如果新令牌是列表中的前一项,则已按下后退按钮。
如果您位于列表的中间(返回几次)并且出现了一个新条目(按下了新链接),请删除列表的其余部分(不能再前进到那里)并添加新的条目 - 和将迭代器移动到该项目。

你明白了。

What you can do is have one UrlManager like this:

   public class UrlManager implements ValueChangeHandler<String> {

   public UrlManager() {
     History.addValueChangeHandler(this);       
    }

  public void onValueChange(ValueChangeEvent<String> event) {     
    String historyToken = event.getValue();

  }
   }

Save every history token to a list.
If it is a completely new history token then add it to the list.
If it is the previous history token, then the back button has been pressed.

I suggest using a list to save the tokens and save an iterator that can move up and down the list. So initially it points at the end of the list. If the new token is the previous item on the list, then the back button has been pressed.
If you're in the middle of the list (back a few times) and a new entry comes in (new link pressed), remove the rest of the list (can't go forward there anymore) and add the new one- and move iterator to that item.

You get the idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文