History

The history API allows your app to manipulate the current page URL for use in navigation

This is only enabled for page modules (Admin page, General page, Configure page, User profile page).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
AP.require(["history"], function(history){

   // Register a function to run when state is changed.
   // You should use this to update your UI to show the state.
   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.
   history.pushState("page2");

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

});

Methods

back ( )

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

Example

1
2
AP.require(["history"], function(history){
   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

1
2
AP.require(["history"], function(history){
   history.forward(); // go forward by 1 entry in the browser history.
});

getState ( )

The current URL anchor.

Returns: String

Example

1
2
AP.require(["history"], function(history){
   history.pushState("page5");
   history.getState(); // returns "page5";
});

go (int)

Goes back or forward the specified number of steps. A zero delta will reload the current page. If the delta is out of range, it does nothing. Will invoke the popstate callback.

Parameters

NameTypeDescription
int

delta

Example

1
2
AP.require(["history"], function(history){
   history.go(-2); // go back by 2 entries in the browser history.
});

popState (Function)

Register a function to be executed on state change.

Parameters

NameTypeDescription
Function callback to be executed on state change

pushState (String)

Pushes the given data onto the session history. Does NOT invoke popState callback.

Parameters

NameTypeDescription
String

URL to add to history

replaceState (String)

Updates the current entry in the session history. Does NOT invoke popState callback.

Parameters

NameTypeDescription
String URL to add to history

Rate this page: