admin管理员组文章数量:1356479
Hi I am using GWT and its standart way to support history via "History" class. It is very convenient but how can I remove anchor part from an url? For example:
My base url:
While using application I move to a place that adds new history item.
In code:
History.newItem("funnygame");
As result:
I change place one more time:
In code:
History.newItem("notsofunnygames");
As result:
Then I want to go back to my home page ().
What should be placed in code?:
????
to get back to:
Is there any standart way I can achieve my goal?
If I add something like this:
History.newItem("");
or
History.newItem(null);
the url will bee
And this is not what I am lloking for, I need it without sharp character.
Hi I am using GWT and its standart way to support history via "History" class. It is very convenient but how can I remove anchor part from an url? For example:
My base url:
http://www.mysuperwebsite./myapp
While using application I move to a place that adds new history item.
In code:
History.newItem("funnygame");
As result:
http://www.mysuperwebsite./myapp#funnygame
I change place one more time:
In code:
History.newItem("notsofunnygames");
As result:
http://www.mysuperwebsite./myapp#notsofunnygames
Then I want to go back to my home page (http://www.mysuperwebsite./myapp).
What should be placed in code?:
????
to get back to:
http://www.mysuperwebsite./myapp
Is there any standart way I can achieve my goal?
If I add something like this:
History.newItem("");
or
History.newItem(null);
the url will bee
http://www.mysuperwebsite./myapp#
And this is not what I am lloking for, I need it without sharp character.
Share Improve this question edited Nov 22, 2012 at 16:42 kapandron 3,6712 gold badges28 silver badges39 bronze badges asked Jan 31, 2011 at 10:18 ZalivakaZalivaka 7632 gold badges13 silver badges20 bronze badges4 Answers
Reset to default 5If you use History.newItem(null);
a new event will be fired.
As a result, you will toggle your home page :
http://www.mysuperwebsite./myapp#
Having or not a # at the end is the same thing, am I wrong ?
EDIT:
...
// Get the last part of the url and remove #token
String s = Location.getHref().substring(Location.getHref().lastIndexOf("/"));
s = s.substring(0, s.indexOf("#")-1);
setToken(s);
...
protected native void setToken(String token) /*-{
$wnd.history.pushState({},'', token);
}-*/;
The anchor is identified by a #
, so you can use the following to remove it:
int index = link.indexOf('#');
if (index != -1) {
link = link.substring(0, index);
}
If you dont want a historytoken you are probably using history wrong. If you're not intending to fiddle with navigation i would remend using GwtEvent / EventHandler. Which is essentially what gwt's History class does, in addition to linking those events to the navigation history.
You can create a tool class, and you call it when History changes.
public class UrlUpdater {
public static void removeHashIfEmpty() {
if(isHashEmpty())
removeHash();
}
private static boolean isHashEmpty() {
return "#".equals(Window.Location.getHash());
}
private static void removeHash() {
updateURLWithoutReloading(Window.Location.createUrlBuilder().setHash(null).buildString());
}
private static native void updateURLWithoutReloading(String newUrl) /*-{
$wnd.history.replaceState({}, null, newUrl);
}-*/;
}
本文标签: javaGWT Remove anchor part urlStack Overflow
版权声明:本文标题:java - GWT. Remove anchor part url - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744018648a2576802.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论