Edit this page

up.viewport up.viewport.saveFocus([viewport], [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.restoreScroll() 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

[viewport]
optional

The viewports for which to save focus state.

Defaults to all viewports within the given layer.

[options.location]
optional

The URL for which to save focus state.

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

string
[options.layer='current']
optional

The layer for which to save scroll positions.

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

string