The IFP Webapp Iframe Communication API (version 2.0.0) enables secure cross-origin communication between an embedded IFP (Interactive Floor Plan) web application and its parent page using the Window.postMessage() mechanism. This JavaScript library facilitates interaction with the IFP webapp.
The API is provided as a JavaScript library that you include in your code. It requires an iframe to host the IFP webapp and initializes a communication channel between the parent page and the embedded application.
To use the API, initialize it by creating an instance of ZONDA.WebappIFPApi with a reference to the iframe hosting the IFP webapp and a callback function to handle initialization results.
The IFP webapp must be loaded in an iframe. Set the iframe's src attribute to the IFP application URL, which typically includes a plan ID. For example:
The API requires time to initialize as it waits for the IFP webapp to load. During this period, you can display a placeholder image or a gray background (as shown in the demo) to improve the user experience. Once initialization is complete, the specified callback function is invoked with a success or error message.
You can confirm that the connection has been successfully established by observing the following messages in the browser console:
Loading: Loading IFP Webapp IFrame Communication API v2.0.1...
Success: [SUCCESS] IFP API connected to IFP application via iframe [ifpIframe] in 1.254 seconds.
List of instance methods available after initializing the WebappIFPApi.
deleteConfig(callbackFunc)
getCurrentOptions(callbackFunc)
getModules(callbackFunc)
getStaticModules(callbackFunc)
loadConfig(userId, callbackFunc)
printBrochure(callbackFunc)
ready(callbackFunc)
reload(callbackFunc)
resetPlan(callbackFunc)
saveConfig(sessionId, userId, callbackFunc)
setActivityFunction(activityCallback)
setAvailables(data, callbackFunc)
setFavoriteCallback(callbackFunc)
setFavorites(data, callbackFunc)
setOptionCallback(callbackFunc)
setOptions(data, callbackFunc)
setRestrictions(data, callbackFunc)
showElevation(callbackFunc)
showFloorplan(callbackFunc)
showRoomDesigner(callbackFunc)
showRoomPlanner(callbackFunc)
showModule(moduleId, callbackFunc): This function can be called in different ways, as shown in the screenshot below, where “elevation” is the module ID and “2” is the module index, with other supporting functions.
onModuleChanged(callbackFunc): This function can be called when either the parent or child window wants a callback regarding actual module changes. It will notify both the parent and child windows about the module change.
When a module changes, it provides the following output. In this callback function, we can handle the module change according to our requirements.
Iframe Not Found: Ensure the iframe ID or DOM reference is correct. Check for typos or timing issues (e.g., referencing the iframe before it is added to the DOM).
Connection Issues: Verify that the IFP webapp URL is accessible and that the parent page and iframe are served over HTTPS to avoid mixed content errors.
Callback Not Triggered: Ensure the callback function is properly defined and that the IFP webapp has finished loading.