---
name: "up.viewport.restoreScroll"
area: "API"
kind: "JavaScript function"
parent: "up.viewport module"
url: "https://unpoly.com/api/up.viewport.restoreScroll"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.viewport module](https://unpoly.com/api/up.viewport.md)</nav>

# up.viewport.restoreScroll([viewport], [options])

Restores [previously saved](https://unpoly.com/api/up.viewport.saveScroll.md) scroll positions.

If no saved scroll position is known, scroll positions are not changed and `false` is returned.

Unpoly automatically restores scroll positions when the user [presses the back button](https://unpoly.com/learn/restoring-history.md).

---

## Parameters {#parameters}

### [viewport] {#viewport}

(optional)

The viewports for which to restore scroll positions.

Defaults to all viewports within the given layer.

Type: [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) | [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Element](https://developer.mozilla.org/en-US/docs/Web/API/Element)>

### [options.layer='current'] {#options.layer}

(optional)

The layer on which to restore scroll positions.

Type: [up.Layer](https://unpoly.com/api/up.Layer.md) | string

### [options.location] {#options.location}

(optional)

The URL for which to restore scroll positions.

If omitted, the given [layer's location](https://unpoly.com/api/up.Layer.prototype.location.md) is used.

Type: string

---

## Return value {#return-value}

Returns whether scroll positions could be restored.

Type: boolean

