Skip to content

Commit

Permalink
DMX-4579 update postmessage example (#267)
Browse files Browse the repository at this point in the history
* Adding uk01 zone to postMessage example and supporting text.

* Additional content
  • Loading branch information
jimj-procoretech authored Nov 5, 2024
1 parent a7d08ff commit 89a4805
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion building_applications/building_side_panel_apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ The information retrieved from a message event sent from the parent window inclu
To access context data using the MessageEvent interface, add an event listener to your page and the `postMessage` method to initialize communication with the parent window.
Here is some example code that demonstrates retrieving context data from the message event object.
Note the use of conditional statements with the `postMessage` method to account for [Multiple Procore Regions]({{ site.url }}{{ site.baseurl }}{% link tutorials/tutorial_mpz.md %}).
Be sure to account for all regions where your application needs to retrieve Procore context.
Be aware that as new Procore regions become available, your `postMessage` code must be updated to support these new regions.

```javascript
window.addEventListener('message', (event) => {
Expand All @@ -350,8 +352,9 @@ window.addEventListener('message', (event) => {
const resource_id = obj.context.id;
}});

if (document.referrer === "https://us02.procore.com/") { window.parent.postMessage({ type: 'initialize' }, "https://us02.procore.com/"); }
if (document.referrer === "https://app.procore.com/") { window.parent.postMessage({ type: 'initialize' }, "https://app.procore.com/"); }
if (document.referrer === "https://us02.procore.com/") { window.parent.postMessage({ type: 'initialize' }, "https://us02.procore.com/"); }
if (document.referrer === "https://uk01.procore.com/") { window.parent.postMessage({ type: 'initialize' }, "https://uk01.procore.com/"); }
```

In the example above we have set the value for the `targetOrigin` parameter of the `postMessage` method to `https://example.com/my-side-panel-app`.
Expand Down

0 comments on commit 89a4805

Please sign in to comment.