function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lodoss1118lodoss1118 

Help needed with getting values from iframe in visualforce page

Hi i am trying to get some values from the send email wizard form within my visualforce page:

 

 

<apex:page >
    
    <script>
        function GetFrameWindow(event)
        {
        	alert(event); 
        	var iFrame = document.getElementById(event);
        	alert(iFrame);
        	var oDoc = iFrame.contentDocument;
        	alert(oDoc);
        }
    </script>
    
    <apex:form >
        <apex:commandButton value="Check" onclick="GetFrameWindow('theIframe');"/>
        <apex:inputTextarea richText="true" cols="2" rows="2"/>
        <center>
            <apex:iframe id="theIframe" src="/_ui/core/email/author/EmailAuthor?p3_lkid=000000011111111&retURL=%2F01111111111111&template_id=1111111111111111&isdtp=mn" scrolling="true" frameborder="true" width="800" height="600"/>      
        </center>
    </apex:form>
  
</apex:page>

 but everytime i try to get something from oDoc it is always null?

 

 

bob_buzzardbob_buzzard

This is because the browser is protecting the user from cross site scripting. As the iframe comes from a different server to your Visualforce page, the browser doesn't allow you to access the values from the DOM.

MadhuGudaMadhuGuda

Hi,

 

Below is my VF Code

 

JS

function getFrameContent(){

var iframe = document.getElementsByTagName('iframe')[0];
                alert(iframe);//working fine
                doc = iframe.contentWindow;
                alert(doc);//working fine
                alert(doc.body);//undefined
                alert(doc.body.innerHTML);

}

<form id="secondForm" name="secondForm" method='POST' enctype='multipart/form-data'
                        action="http://someurl" target="responseFrame" >

</form>

<input type="button" name="btnid" value="Test To Get Frame Data" onclick="getFrameContent()" />

From this I am getting response into IFrame.

 

After that I need to get the data from Iframe.

Plase provide JS code such that I can access frame content./  Where I did mistake.

But in normal html page it is working fine.

 

ThankU.

 

Regards,

Madhusudhan.

 

bob_buzzardbob_buzzard

If you are attempting to access the contents of an iframe from a different server to that where the javascript is served from, you cannot do this.