Link to home
Create AccountLog in
Avatar of roscoe_p
roscoe_p

asked on

getting IFRAME content

get iFrame content

How do I read the content from an iFrame when the page loads before its visible?

In JavaScript I am trying to read the content from an iFrame after the content has been loaded into the iFrame but before the page displays.

I am using the following function to retrieve the content.

<script language="JavaScript" type="text/javascript">

Function getIframeContent()
{
content = frames[iFView].document.body.innerHTML;

alert(content);
};

 </script>

where iFView is the frame name. I call this function at the very end of the HTML page, long after the code for loading the iFrame is run.
When the page loads the alert box comes up empty. Once the page is visible and if I call this same function again from an onclick=getIframeContent() in a button element, I get the iFrame content displayed in the alert box just fine.

What do I need to do to get it to work while the page isnt visible?
ASKER CERTIFIED SOLUTION
Avatar of ChetOS82
ChetOS82
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
But be aware. If you do not add the src= attribute like I omitted then your onLoad will be called with an empty iframe page. You see?

No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup Zone:
 Split: ChetOS82 {http:#19234107} & Zvonko {http:#19403216}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

L00M
Experts Exchange Cleanup Volunteer