View
 

Getting out of the IFrame


As an App developer you may need to access the parent iframe. Same Origin Policy isolates each iframe and doesn't give the child access to it. Which most of the time is a good thing.

 

2Performant implements a cross-iframe communication channel based on postMessage. This allows you to send commands to the parent iframe, and if it's supported by the implementation it will be executed.

 

How to Use It

 

Step 1/2

Add the postMessage library to your app headers:

 

<script type='text/javascript' src='http://sandbox.2performant.com/javascripts/postmessage.js'></script>

 

Step 2/2

Somewhere in your App:

 

<script type='text/javascript'>

  xtd_receive_message_from_parent();
</script>

 

Running Commands

 

When you execute a command you send an array that looks like [ "command_name", "callback", "opts" ]. "opts" depend on the type of command you are interested in.

 

For example:

// [ CMD, callback, width, height ]
msg = [ "resize", "after_resize", null, 30 ]; // or window.scrollheight instead of 30
xtd_send_message_to_parent(msg);

 

This tells the parent to resize your iframe to 30px in height and then callback your method after_resize().

 

Available Commands

 

resize

Should be used to resize the child iframe to any width/height.

 

Send [ "resize", "callback_method", "width (size or null)", "height (size or null)" ]

 

Callback method will not receive any returned arguments.

 

receive_data

Use it to send data to the parent from the child iframe. To protect regular DOM methods, the parent function that gets called with the result must start with dp_.


Send [ "receive_data", null, "data", "parent callback function (eg 'dp_cookie_result')" ]

 

Other Commands

 

If you need any other commands let us know. We add them as we get requests from developers.