Jason
Jason

Reputation: 7682

postMessage - multiple postMessage events/functions/callbacks?

Looked at this Q & A, but it doesn't solve for my issue: PostMessage with multiple functions or custom callbacks

I need to use postMessage on load and then another within a click event, and the receiver for both would be on the same page (parent).

Is there a method to scope postMessage? or to send multiple postMessages? I can parse the message to trigger specific functions, but how to have multiple posts?

Thanks

Upvotes: 2

Views: 7952

Answers (1)

Jason
Jason

Reputation: 7682

My postMessage:

    $.postMessage(
        'layerTitle|'+ layerTitle +'',
        '*',
        parent
      );
...
var getDocHeight = $(document).height();
     $.postMessage(
        'iframeHeight|'+ getDocHeight +'',
        '*',
        parent
      );

and my receive:

$.receiveMessage(
  function(e){
    var message = e.data.split('|');
    if(message[0] == "layerTitle"){
    $('#ui-dialog-title-loginDialog').empty().append(message[1]);
    }
    if(message[0] == "iframeHeight"){
        $('#loginLayer').attr('height', message[1]);
    }

  }
);

Upvotes: 1

Related Questions