Code to direct to correct embed url

I would like to create code that pulls the Organisation from a Users Profile page, say “OrgCode” and uses that parameter within an if statement embed url such as below:

var OrgCode = Pulled from the “OrgCode” field within the Users Profile collection

if ( OrgCode === 1)
{ }

else if ( OrgCode === 2)
{ }


Please could you advise what I am missing, in particular how to write the code to get the variable OrgCode and whether the embed code would work as written. Thanks in advance.


Hi Sean,
You need to use html code element.
Try this sample example:

    <script type="text/javascript">
        window.onmessage = (event) => {
            if ( {
                const iframe = document.getElementById("myIframe");
                iframe.src =;
<iframe id="myIframe" src=""></iframe>

In order to pass the information to the html element you need to use postMessage method.


For more Information read here
Feel free to paste your code here.
Good luck!


Thank you for your quick reply Roi.
Where would I put the variable “OrgCode” in the script above?

1 Like

Ive tried this with some advice within the page code. Unfortunately it isnt working. Please could you check to see what is missing? Thanks in advance.

(function () {
function createIFrame() {
var OrgCode = document.getElementById(‘input1’);
var iFrame = document.getElementById(‘OrgFrame’);
var targetSrc = OrgCode.value;
switch (targetSrc) {
case ‘TEMP1’:
iFrame.src = ‘URL1’;
case ‘TEMP2’:
iFrame.src = ‘URL2’
iFrame.src = ‘URL3(which would include the OrgCode value)’;

window.addEventListener('DOMDocumentLoaded', createIFrame); 


Thanks Roi. Ive taken a look at the link for post message and am still struggling to understand how it should be actually written in the HTML embed code and in the page code. Would you be able to help me with the actual text for both?

Awesome complete example that works. I am looking for something similar to the reverse. I need an example of updating the parent window location but when the src URL changes. Any chance that’s easy for you?