> For the complete documentation index, see [llms.txt](https://docs.ipaper.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ipaper.io/flipbook-javascript-api/legacy-javascript-api-v2/commands.md).

# Commands

Commands are instructions issued by the parent window to the iframed flipbook. Commands can be invoked by calling magic methods, which can be accessed directly from the API instance.

## Overview

![](https://3504352165-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FW0UCgeNLp5UrqOZTjvsN%2Fuploads%2F4aUdn5VnTlBfawOnAq68%2Fcommands.svg?alt=media\&token=229ae843-709c-4e65-9802-fabe1931926e)

Commands are issued from the parent window (your website) to the JavaScript API. The API then relays the command via `window.postMessage()` to the iframed flipbook.

## Flipbook-related commands

### `updateEventSettings`

It is possible to dictate how the iframed flipbook should handle events when they have been triggered. The method accepts a single argument that is an object containing the following keys, which references events that the v2 Flipbook API listens to:

* [`onBasketClick`](/flipbook-javascript-api/legacy-javascript-api-v2/events.md#onbasketclick)
* [`onItemAdd`](/flipbook-javascript-api/legacy-javascript-api-v2/events.md#onitemadd)

The keys should contain an object of the following format: `{ preventDefault: <boolean> }`, where `<boolean>` is `true` or `false`. When `preventDefault` is set to `true`, the flipbook will skip the default action associated with each event. If set to `false`, the default action will be performed.

| Event                                                                                        | Default action taking place in the flipbook                                                                             |
| -------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| [`onBasketClick`](/flipbook-javascript-api/legacy-javascript-api-v2/events.md#onbasketclick) | Opens the shop basket                                                                                                   |
| [`onItemAdd`](/flipbook-javascript-api/legacy-javascript-api-v2/events.md#onitemadd)         | <p>Adds the item to the shop basket.<br>Triggered by any enrichment that adds a shop item (e.g. shop variant menu).</p> |

An example use:

```javascript
// Disable opening of shop basket AND adding shop items
iPaperAPI.updateEventSettings({
	onBasketClick: { preventDefault: true },
	onItemAdd: { preventDefault: true }
});
```

## Publication-related commands

### `goToPage`

Navigate to a specific page: the page number is to be provided as the one and only argument of the function. For example:

```javascript
iPaperAPI.goToPage(4);
```

### `goToPreviousPage`

Go to the previous spread (if flipbook has a spread-based layout), or the previous page (if flipbook has a page-based layout). This method accepts no arguments:

```javascript
iPaperAPI.goToPreviousPage();
```

### `goToNextPage`

Go to the next spread (if flipbook has a spread-based layout), or the next page (if flipbook has a page-based layout). This method accepts no arguments:

```javascript
iPaperAPI.goToNextPage();
```

## Shop-related commands

### `addItem`

Programmatically adds a custom item to the basket. This method accepts a single argument, consisting of properties of the shop item entity.

| Property      | Type     | Description                                |
| ------------- | -------- | ------------------------------------------ |
| `title`       | `string` | Shop item title                            |
| `description` | `string` | Shop item description                      |
| `productID`   | `string` | Shop item product ID                       |
| `originPage`  | `number` | Page number where the shop item is located |
| `price`       | `number` | Shop item price                            |
| `quantity`    | `number` | Number of items added                      |

Example use:

```javascript
iPaperAPI.addItem({
    title: 'My product',
    description: 'Product description',
    productID: 'PROD-25B',
    price: '29.95',
    originPage: 6,
    quantity: 1
});
```

## Advanced use

If you are accustomed to the `.trigger()` regime (such as that implemented in JQuery), you can also use it as such:

```javascript
iPaperAPI.trigger('goToPage', 4);
```

Refer to [**Event listeners and command triggers**](/flipbook-javascript-api/legacy-javascript-api-v2/advanced-usage.md#event-listeners-and-command-triggers) on the advanced usage page for a wholesome example.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ipaper.io/flipbook-javascript-api/legacy-javascript-api-v2/commands.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
