up.viewport up.viewport.saveFocus([options])
JavaScript function

Saves focus-related state for later restoration.

Saved state includes:

  • Which element is focused.
  • The cursor position within a focused input element.
  • The selection range within a focused input element.
  • The scroll position within a focused input element.

State can only be preserved if the focused element is targetable.

Saved state will be associated with the given layer's location. It can later be restored by calling up.viewport.restoreFocus() at the same location, or by following a link with an [up-focus="restore"] attribute to that same location.

Unpoly automatically saves focus-related state before navigating.


Parameters

[options.location]
optional

The URL for which to save focus state.

If omitted, the given layer's location is used.

Type: string
[options.layer='current']
optional

The layer for which to save focus state.

If omitted, state for the current layer will be saved.

Type: string