How to access community data inside a custom widget
Introduction
This article shows developers how they may access Igloo community data from inside a custom widget.
Note: Custom widgets are rendered on the page inside an iframe, thus functions of the parent document/window are not directly accessible by the logic inside your widget.
Tip: Since the iframe that contains the widget is rendered directly on the page from the same domain, there are no CORs issues and this document outlines how to modify your code to access the parent document/window.
How to retrieve community data
Use the following code to access community data inside your custom widget (Fig. 2.1):
/**
* @description Use this JavaScript inside your widget to access community data
*/
var communityData = window.parent.Igloo.communityData
/** Your custom code here... */
console.log(communityData);
(Fig. 2.1) Access community data within a custom widget.
Output
The above script will output the following data for developers to work with (Fig 3.1):
(Fig. 3.1) Console output of community data.
FAQ
To learn more about how an iframe can interact with the parent document, and vice-versa, check out this MDN article
- 410 views
- 2 versions
- 0 comments
- 1 follower
- Updated By:
- Matthew Seabrook
- September 26, 2017
- Posted By:
- Matthew Seabrook
- September 26, 2017
- Versions:
- v.2
0 Comments