Help center / Opening the pop-up programatically with JavaScript

Opening the pop-up programatically with JavaScript

You can open the checkout pop-up programatically with JavaScript. This means you can attach it to any element, click, mouse event, state change and so on.

Start by adding the pop-up script to your site

Checkout Page will add a checkoutPage object to the window. Inspect it by running window.checkoutPage.

To open a checkout, execute this:

  window.checkoutPage.open({ seller: '{SELLER_NAME}', checkout: '{CHECKOUT_SLUG}' });

To close any open checkouts, execute this:

  window.checkoutPage.close();

In more advanced scenerio's, you may have to check if the window and window.checkoutPage exists before trying to execute the open and close functions. You can do that like so:

  if (typeof window !== 'undefined' && typeof window.checkoutPage !== 'undefined) {
    window.checkoutPage.open({ seller: '{SELLER_NAME}', checkout: '{CHECKOUT_SLUG}' });
  }

  if (typeof window !== 'undefined' && typeof window.checkoutPage !== 'undefined) {
    window.checkoutPage.close()
  }

Need more help?

Contact us via the Chat in the bottom-right corner or via email on support@checkoutpage.co