function Communicator() {
useEffect(() => {
async function onReceiveCommunication(querystr) {
console.log('onReceiveCommunication', querystr)
var params = parseQueryString(querystr);
switch (params["action"]) {
case "successfulSave":
window.parent && window.parent.parent && window.parent.parent.postMessage(
{
event_id: 'successfulSave',
data: {
v1: false,
// v2: 'value2'
}
},
)
break;
case "cancel":
window.parent && window.parent.parent && window.parent.parent.postMessage(
{
event_id: 'cancel',
data: {
v1: false,
// v2: 'value2'
}
},
)
break;
case "transactResponse":
var response = params["response"];
//console.log("res",params)
window.parent && window.parent.parent && window.parent.parent.postMessage(
{
event_id: 'transactResponse',
data: {
v1: response,
v2: false,
}
},
)
break;
case "resizeWindow":
// var w = parseInt(params["width"]);
// var h = parseInt(params["height"]);
// var ifrm = iframeAuthorizeNet;
// ifrm.style.width = w.toString() + "px";
// ifrm.style.height = h.toString() + "px";
// centerPopup();
break;
}
};
function parseQueryString(str) {
var vars = [];
var arr = str.split('&');
var pair;
for (var i = 0; i < arr.length; i++) {
pair = arr[i].split('=');
vars.push(pair[0]);
vars[pair[0]] = unescape(pair[1]);
}
return vars;
}
function callParentFunction(str) {
if (str && str.length > 0)
{
// Errors indicate a mismatch in domain between the page containing the iframe and this page.
onReceiveCommunication(str)
}
}
function receiveMessage(event) {
if (event && event.data) {
callParentFunction(event.data);
}
}
if (window.addEventListener) {
window.addEventListener("message", receiveMessage, false);
} else if (window.attachEvent) {
window.attachEvent("onmessage", receiveMessage);
}
if (window.location.hash && window.location.hash.length > 1) {
callParentFunction(window.location.hash.substring(1));
}
}, [])
return (
<>
</>
)
}