iframes on your website can use the commands provided by the CMP API.
They can do this by making calls to the parent's (or ancestor's) frame that the CMP is loaded on, sending the commands as a message with the postMessage() function.
The frame to make the call to can be determined by the ancestor by looking for a.frames["__tcfapiLocator"] child.
Send a command
The message to send should have the below form where the __tcfapiCall object holds the information about the command to execute.
command and parameter are the same as the parameters passed to the __tcfapi() function, and callId est un ID unique à déterminer.
{ __tcfapiCall: { command:*command*,// name of the command to execute version:2,// version of the TCF specification parameter:*parameter*,// parameter to be passed to the command function callId:*uniqueId*// unique call ID }}
Before sending messages, the iframe must define a JavaScript function to execute when a message is sent back. To do this, it must add a listener for the event message with the window.addEventListener() function.
By doing this, it will be able to receive and process the command result in __tcfapiReturn.
Thewindow.addEventListener()function is different from the addEventListener command, which is included in the CMP API.
When a command is sent, the returned message (event.data) holds the __tcfapiReturn object with the command result.
returnValue and success are the same as the parameters passed to the callback of the __tcfapi() function, and callId is the ID from the origin call (__tcfapiCall).
{ __tcfapiReturn: { returnValue:*returnValue*,// result of the command success:*boolean*,// true if the call to the command was successful callId:*uniqueId*// call ID sent in the __tcfapiCall }}