Documentation

history

The History API allows your add-on to manipulate the current page URL for use in navigation. When using the history module only the page anchor is modified and not the entire window location.

Note: This is only enabled for page modules (Admin page, General page, Configure page, User profile page). It cannot be used if the page module is launched as a dialog.

Example

// Register a function to run when state is changed.
// You should use this to update your UI to show the state.
AP.history.popState(function(e){
    alert("The URL has changed from: " + e.oldURL + "to: " + e.newURL);
});

// Adds a new entry to the history and changes the url in the browser.
AP.history.pushState("page2");

// Changes the URL back and invokes any registered popState callbacks.
AP.history.back();

Methods

back()

Goes back one step in the joint session history. Will invoke the popState callback.

Example
AP.history.back(); // go back by 1 entry in the browser history.

forward()

Goes back one step in the joint session history. Will invoke the popState callback.

Example
AP.history.forward(); // go forward by 1 entry in the browser history.

getState() → {String}

Retrieves the current state of the history stack and returns the value. The returned value is the same as what was set with the pushState method.

Returns:

The current url anchor

String
Example
AP.history.pushState("page5");
AP.history.getState(); // returns "page5";

go(delta)

Moves the page history back or forward the specified number of steps. A zero delta will reload the current page. If the delta is out of range, does nothing. This call invoke the popState callback.

Parameters:
Name Type Description
delta Integer

Number of places to move in the history

Example
AP.history.go(-2); // go back by 2 entries in the browser history.

pushState(url)

Updates the location's anchor with the specified value and pushes the given data onto the session history. Does not invoke popState callback.

Parameters:
Name Type Description
url String

URL to add to history

replaceState(url)

Updates the current entry in the session history. Updates the location's anchor with the specified value but does not change the session history. Does not invoke popState callback.

Parameters:
Name Type Description
url String

URL to update current history value with

popState(callback)

Register a function to be executed on state change.

Parameters:
Name Type Description
callback function

Callback method to be executed on state change.