0

I am showing different domain website on iFrame window in my visualforce page. There is a button on that website "SAVE" (let's say). Once cx clicks on save button, I should notify too. How do I get this done? Java developer said he will be sending using parent.postMessage and I am using below sample to get it. but the problem is I am not using any kind of button from visualforce.

<apex:page standardController="Quote" Extensions="Quote_Iframe" sidebar="false">
<script>
     if (window.addEventListener) {
            window.addEventListener("message", handleMessage);
     } else {
            window.attachEvent("onmessage", handleMessage);
       }
       function handleMessage(event) {
            console.log("Received a message from " + event.origin + ".");

            var messageFromSender = event.data;
          <!--  document.getElementById("{!$Component.hdnField}").value = "messageFromSender"; -->
            console.log(messageFromSender);
        }
 </script>

 <apex:form >
 <apex:inputHidden id="hdnField" value="{!retValue}" />
 <center><apex:commandButton value="Back to Quotes" action="{!back}"/></center> 
   <!--<apex:detail relatedList="true" title="true" inlineEdit="true"/> <br/>-->
   <apex:iframe src="{!Url}" scrolling="true"/> 

 <center><apex:commandButton value="Back to Quotes" action="{!back}"/></center>


can anyone tell me how to get that value to Controller without using command button.. Thanks a ton.

2
  • Are you getting that value in JavaScript? Sep 26, 2018 at 6:03
  • @TusharSharma Yes. I am getting the value. I can see the message in console Log if I hide document.getElementById part.
    – AshSFcloud
    Sep 26, 2018 at 7:46

1 Answer 1

0

Just create an apexFunction and pass the data in the controller

<apex:actionFunction name="paraFunction" action="{!controllerMethodName}" rerender="view">       
     <apex:param id="anode" name="node" value="" />
</apex:actionFunction> 

and call this function from your script

paraFunction(messageFromSender);

and in your controller, get value using parameter

String para = Apexpages.currentPage().getParameters().get('node');
1
  • It worked. Thank you very much. I should read more details about apex:param
    – AshSFcloud
    Sep 26, 2018 at 10:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .