# JavaScript API

> Open popups, listen for events, control embeds programmatically.

Once the SDK loads, `window.Maxforms` is a function you call with a command and arguments. All calls are safe to make before the SDK finishes loading — they queue and replay automatically.

## 1. openPopup

```js
Maxforms('openPopup', {
  formId: 'YOUR_FORM_CODE',
  position: 'center',        // 'center' | 'bottom-right'
  width: 560,
  overlay: true,
  hideOnSubmit: true,
  hideOnSubmitDelay: 1500,   // ms; only applies when hideOnSubmit is true
  showTitle: false,
  alignLeft: false,
  transparentBackground: false,
  trackEvents: true,
  hiddenFields: {            // pre-fill declared hidden fields
    ref: 'launch',
    utm_campaign: 'spring'
  },
  onSubmit: function (payload) {
    // payload = { formId, embedId, submissionId, page }
  }
});
```

## 2. closePopup

```js
Maxforms('closePopup', 'YOUR_FORM_CODE');
// or
Maxforms('closePopup', { formId: 'YOUR_FORM_CODE' });
```

## 3. on / off

Subscribe to lifecycle events:

```js
function handleSubmit(payload) {
  console.log('Form submitted:', payload.formId, payload.submissionId);
}

Maxforms('on', 'maxforms.form.submitted', handleSubmit);

// Later:
Maxforms('off', 'maxforms.form.submitted', handleSubmit);
```

See [Events](/developers/embed/events) for the full event vocabulary.

## 4. init

Reserved for future features (e.g. team-level keys). In v1 it's a no-op and you don't need to call it.

```js
Maxforms('init', { teamKey: 'reserved-for-future-use' });
```

