GWT: How to suppress hyperlink so that it doesn't change my history token

南楼画角 提交于 2019-12-12 12:13:20

问题


I want to make my hyperlinks act like buttons (only respond to Click event) however, they change the history token automatically when you click on them, which messes up my history mechanism in my application. Is there a way to suppress the default behaviour of the hyperlink so it doesn't change the history token? I tried setting targetHistoryToken to null but it didn't work.

Thanks,


回答1:


Use Anchor instead.

As java doc of Hyperlink says:

If you want an HTML hyperlink ( tag) without interacting with the history system, use Anchor instead.




回答2:


The easiest way by far to do this is to create your own class that extends Composite, and just renders an <a> </a> as a HTML widget. I had this same problem and that's how I got around it.




回答3:


Like rustyshelf says,

final HTML contactLink = new HTML(""
          + contactName + "");
contactLink.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
  .....
 }
}

http://gwt.google.com/samples/Showcase/Showcase.html#CwStackPanel




回答4:


Just remove href="" from Anchor.

<g:Anchor ui:field="clickField">Click here</g:Anchor>



回答5:


I created this class

import com.google.gwt.user.client.ui.HTML;

public class HyperlinkWithoutHistoryToken extends HTML {
    public HyperlinkWithoutHistoryToken(String html, boolean wordWrap) {
        super("<a href=\"javascript:undefined;\">" + html + "</a>", wordWrap);
    }
    public HyperlinkWithoutHistoryToken(String html) {
    super("<a href=\"javascript:undefined;\">" + html + "</a>");
    }
}


来源:https://stackoverflow.com/questions/825712/gwt-how-to-suppress-hyperlink-so-that-it-doesnt-change-my-history-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!