0

My iframe Code Link is http://example.org?pd=123

            var currentHeight = $('.comments_holder').outerHeight();
            var parent = window.parent;
            var targetOrigin = "my parent site link";
            if (parent && parent.postMessage) {
                parent.postMessage(currentHeight, targetOrigin);
            }

From this i need to pass the height of the div to the main site

And now i also want to pass another parameter to main site

                var count = 123;
                var parent = window.parent;
                var targetOrigin = "my parent site link";
                if (parent && parent.postMessage) {
                    parent.postMessage(count , targetOrigin);
                }

And my code in main site i.e. single.php of wordpress site

<script>
jQuery(document).ready(function($){
window.addEventListener('message', receiveMessage, false);

function receiveMessage(event)
{

what will if else condition here to get both the values 

} 

});
</script>

NOTE i cant check based on event.origin as the link are containing parameters for eg example.com?pd=123

And this link could be changing

Vaibs_Cool
  • 5,820
  • 5
  • 24
  • 59

1 Answers1

1

You'd pass the set of items through as an object:

parent.postMessage({'height': currentHeight, 'stuff': 'foo'}, targetOrigin);

In your example "event.data" would contain the passed object. For example:

function receiveMessage(event) {
   console.log(event.data.height);
}

See https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage#The_dispatched_event for more detail.

joeltine
  • 1,655
  • 14
  • 15