beforeClose: function( event, ui ) {
let phoneContext = $(`#ThePhone${imeiNo}`).get(0).contentWindow;
phoneContext.postMessage({action: 'callFunction'},"*");
//callCount=phoneContext.countSessions(0);
function handleMessageEvent(e) {
callCount = e.data.callCount;
alert(callCount);
console.log("Call count from iframe:", callCount);
if (callCount > 0) {
console.warn("You are on a call:", callCount);
alert("You are on a call, please end the call before closing this window.");
windowObj.dialog("open");
}
// Detach the event listener after it's executed
window.removeEventListener("message",handleMessageEvent);
}
// Attach the event listener
window.addEventListener("message", handleMessageEvent);
}
Instead of callCount=phoneContext.countSessions(0); I'm passing this data from child to parent. First time while on call countSessions(0) is returning 1, but further it returns 0.
I am facing the following problem: Blocked a frame with origin from accessing a cross-origin frame. Thats why I'm passing the data from child to parent using window.parent.postMessage.
popup.html
Code included in phone.js,
Instead of callCount=phoneContext.countSessions(0); I'm passing this data from child to parent. First time while on call countSessions(0) is returning 1, but further it returns 0.
I am facing the following problem: Blocked a frame with origin from accessing a cross-origin frame. Thats why I'm passing the data from child to parent using window.parent.postMessage.