Skip to content

Commit

Permalink
Updating postMessage example to account for multiple procore regions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jimj-procoretech authored Feb 2, 2024
1 parent 97528bc commit 40a4cb4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions building_applications/building_side_panel_apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,9 @@ The information retrieved from a message event sent from the parent window inclu
- Resource ID = event.data.context.id
- View = event.data.context.view

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.
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 %}).

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

window.parent.postMessage({ type: 'initialize' }, 'https://example.com/my-side-panel-app');
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/"); }
```

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 40a4cb4

Please sign in to comment.