HistoryPopStateEvent"

From Documentation
Line 48: Line 48:
 
}
 
}
 
</source>
 
</source>
* Line 12: Desktop object provide pushHistoryState API to push history status.
+
* Line 12: Desktop object provides pushHistoryState API to push history status.
 
* Line 15: Listening on the onHistoryPopState event.
 
* Line 15: Listening on the onHistoryPopState event.
 
* Line 17: Get history state object map.
 
* Line 17: Get history state object map.

Revision as of 07:14, 31 October 2017


HistoryPopStateEvent

HistoryPopStateEvent

Employment/Purpose

The history pop state event used with onHistoryPopState to notify that user pressed BACK, FORWARD or others that causes the history changed (but still in the same desktop).

All root components of all pages of the desktop will receives this event.

Example

Catch a HistoryPopStateEvent in a MVC controller

<zk>
    <window id="win" apply="org.zkoss.MainController">
        <label id="lbl">Handle history states in MVC fashion.</label>
        <button id="btnHistoryAdd">Add History</button>
    </window>
</zk>
public class MainController extends SelectorComposer<Window> {
	private int position = 1;

	@Wire
	private Label lbl;

	@Listen("#btnHistoryAdd")
	public void addHistory() {
		Map<String, Integer> map = new HashMap<String, Integer>();
		map.put("f1", position);
		map.put("f2", "Clicked: " + System.currentTimeMillis());
		getSelf().getDesktop().pushHistoryState(map, "", "?p" + position);
	}

	@Listen("onHistoryPopState = #win")
	public void handleHistoryPopState(HistoryPopStateEvent event) {
		Map<String, ?> state = (Map<String, ?>) event.getState();
		if (state != null) {
			lbl.setLabel(state.get("f2"));
		}
	}
}
  • Line 12: Desktop object provides pushHistoryState API to push history status.
  • Line 15: Listening on the onHistoryPopState event.
  • Line 17: Get history state object map.

Supported events

Name
Event Type
None None

Supported Children

*NONE

Use cases

Version Description Example Location
     

Version History

Version Date Content
8.5.0 Oct 2017 ZK-3711: Support HTML5 history API



Last Update : 2017/10/31

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.