GWT. Set url without submit

后端 未结 3 561
太阳男子
太阳男子 2021-01-18 06:35

Can i change url(set parameter) without submit? I found this method http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/user/client/Window.Location.html#

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-18 07:24

    If you want to change something that is not in the hash, for example you want to change a parameter in the URL, you can do it like this!

    private void someMethod() {
        String newURL = Window.Location.createUrlBuilder().setParameter("someParam", "someValue").buildString();
        updateURLWithoutReloading(newURL);
    }
    
    private static native void updateURLWithoutReloading(String newUrl) /*-{
        $wnd.history.pushState(newUrl, "", newUrl);
    }-*/;
    

    Then you could register a function that handles the user using the back and forward browser buttons as demonstrated here.

提交回复
热议问题