4

is it possible to remove a History item in gwt? What i want to achieve is that in a special case pressing the browsers back button will show up the second history item from back. I know i can do it by manually calling History.back();, but i don't like that because the user will see the transition for a second or so which is not nice. Thx in advance for help.

kuku

kapandron
  • 3,546
  • 2
  • 25
  • 38
kukudas
  • 4,834
  • 5
  • 44
  • 65
  • Why putting the token on the history stack in the first place if it shouldn't be accessible by the user? – z00bs Oct 19 '10 at 10:56
  • The problem is by the time i put the token in i do not know if it should be added or not. – kukudas Oct 19 '10 at 10:58

3 Answers3

7

No the browsers do not allow this.

GWT uses Javascript (of course) to manipulate the browser history. The Javascript engines do not allow the removal of history entries.

Maybe you could make a HistoryListener to skip the step you want removed, but you would have to keep track of history yourself in order to decide which way to skip (forward or backward)

Fedearne
  • 7,049
  • 4
  • 27
  • 31
0

As stated above, this isn't possible via GWT but you can manage this using History

(note: HistoryListener - mentioned in the previous post - has been deprecated)

Here is a simple example that will get you started.

public class UrlManager implements ValueChangeHandler<String> {

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

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

}

fergal_dd
  • 1,486
  • 2
  • 16
  • 27
0

You can use History.replaceItem(newToken, fireEvent).

This will replace the current history token on top of the browsers history stack.
newToken - history token to replace current top entry
fireEvent - a boolean for whether you want to fire history state event or not

ar01
  • 1
  • 1