Some test text!

Hamburger Icon

Web / Guides / Loading WebViewer from another domain

Loading WebViewer from another domain

It may be necessary to share the WebViewer library files amongst various apps and domains (ex. update convenience or security policy). You can load WebViewer's lib folder from another domain by setting the path constructor option to an absolute URL (e.g.

  path: '',
}, document.getElementById('viewer'))
  .then(instance => {});

When you call an API on the WebViewer object, behind the scenes it reaches into the iframe and calls functions in that context. This is fine in a normal scenario where WebViewer and your app are on the same domain. However, the WebViewer library is now hosted on a different domain and the iframe will be pointing to that host domain as its source. When the iframe is on a different domain, then cross origin script access applies and WebViewer will no longer be able to call functions inside the iframe due to security limitations.

For example, the following will occur:

  .then(instance => {
    // instance is undefined!

In this case you have two options to interact with and customize WebViewer.

  1. Run your custom code in a config file . Config files are loaded and executed inside the iframe so they run in the iframe's context and have no problem accessing the APIs. Make sure to follow this step so that the config file is able to be loaded.

  2. Use the window postMessage API to communicate between your page and the iframe. For example, you could send a message to the iframe with the value being the URL to the document you want to load. The iframe would handle this message in a config file and call instance.UI.loadDocument to load the document from the new URL.

Get the answers you need: Chat with us