I have a situation where I need to reDirect the lightning page to record detail page once BACK button in iFrame is clicked. So, Java team was sending a postMessage from the page which I am opening it in an iFrame in Lightning. I am using below code to receive message from that child window.

doInit : function(component, event, helper) {
    var iFrameUrl = 'SOME URL which I am opening in iFrame';
    window.addEventListener("message", function(event) {
      var retValue = event.data;
      console.log('task Value:: '+retValue.task);
      console.log('docId:: '+retValue.docId); })

I am supposed to get the event.data only once I click on BACK button but it is firing like a lot of times with undefined values right after opening the iFrame page until I close it. "task value:: undefined" and "docId:: undefined" console logs are keep going very fast. But, Once I click on BACK button, I am able to get the response with values. "task Value:: 'GoBack'" and "docId:: 9988" as Java team sending but I am unable to make action.getCallback as the window.addEventListener keep firing with undefined values rapidly. What I am missing?? Java team says that they are doing postMessage only while clicking the button. I stuck with this without any trace. Please help. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.