# Javascript API

#### Single Page **Web** Apps

If you have a single page website you can still use Zigpoll. All you need to do is run the following code immediately **after** you change a page within your app.

```javascript
window.Zigpoll.refresh();
```

#### Programmatically Toggle The Poll

If you want to toggle your Zigpoll programmatically (like when a user clicks a button) use the following function.

```javascript
window.Zigpoll.toggle();
```

This will toggle your Zigpoll open and closed.

Alternatively you can use:

```
window.Zigpoll.open();
window.Zigpoll.close();
```

To open and close the Zigpoll respectively.

#### Trigger Event Once Zigpoll Is Loaded

To trigger some behavior once the Zigpoll has loaded, use the onload parameter of the Zigpoll object. For example:

```
window.Zigpoll.onload = function () { console.log('Zigpoll loaded') }
```

This will run once immediately after the Zigpoll has been loaded on your page.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zigpoll.com/javascript-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
