English
Appearance
English
Appearance
For full function signatures, see:
There are two ways to open a scene: automatically or manually.
If the page contains this structure, the plugin script opens it automatically:
<script src="https://www.kivicube.com/lib/iframe-plugin.js"></script>
<iframe id="kivicubeScene" scene-id="7A43keFojH0v98xvFP2w52aF8Y67Zbb5"></iframe>Automatic opening requires:
iframe.id === "kivicubeScene"scene-idiframe already exists before DOMContentLoaded fires<script src="https://www.kivicube.com/lib/iframe-plugin.js"></script>
<iframe id="sceneHost"></iframe>
<script>
const iframe = document.getElementById('sceneHost');
kivicubeIframePlugin.openKivicubeScene(iframe, {
sceneId: '7A43keFojH0v98xvFP2w52aF8Y67Zbb5',
hideLogo: true,
hideTitle: true,
cameraPosition: 'back',
});
</script>Characteristics of openKivicubeScene():
HTMLIFrameElementiframe.id, iframe.allow, and iframe.src{ id, allow, src }There is also a third parameter, modifyIframe = true. If you pass false, you can get the generated src and allow without immediately writing them back to the iframe element:
const result = await kivicubeIframePlugin.openKivicubeScene(iframe, {
sceneId: '7A43keFojH0v98xvFP2w52aF8Y67Zbb5',
}, false);
console.log(result.src, result.allow);This is better suited to debugging or custom wrappers such as Vue / React components. For normal integrations, the default behavior is usually fine.
Collections work the same way as scenes. You only need to switch to the collection-specific API and identifier:
<iframe id="kivicubeCollection" collection-id="b46rfc"></iframe>Or open one manually:
await kivicubeIframePlugin.openKivicubeCollection(iframe, {
collectionId: 'b46rfc',
hideLogo: true,
hideGyroscopePermission: true,
});The main differences are:
hideGyroscopePermission, while scenes do notIn most cases, you should listen for the ready event on the iframe:
iframe.addEventListener('ready', (event) => {
console.log(event.detail);
});For scenes, event.detail.api gives you the advanced scene API.
For collections, event.detail.api also gives you an advanced API, but its interface differs from the scene version.
The recommended pattern is:
iframe.src = 'https://www.kivicube.com/lib/empty.html';
kivicubeIframePlugin.destroyKivicubeScene(iframe);If your flow removes the iframe node entirely, that is fine too, but manually calling destroyKivicubeScene() on the host side is still required.
Collections follow the same pattern:
iframe.src = 'https://www.kivicube.com/lib/empty.html';
kivicubeIframePlugin.destroyKivicubeCollection(iframe);In real projects, it is usually best to wrap "open" and "close" into two functions instead of repeating the same code in multiple places:
export async function openScene(iframe, sceneId) {
return kivicubeIframePlugin.openKivicubeScene(iframe, { sceneId });
}
export function closeScene(iframe) {
iframe.src = 'https://www.kivicube.com/lib/empty.html';
kivicubeIframePlugin.destroyKivicubeScene(iframe);
}