Click to See Complete Forum and Search --> : Iframe Troubles
nealc99
March 4th, 2006, 11:01 AM
Pulling my hair out - HELP!!!!
Along the same lines of this topic....
I'm trying to pull the HTML (source code) of an IFRAME and haven't been able to do it as of yet.
<html>
<head>
<title>Untitled</title>
</head>
<body>
<iframe name="fxrates" src="http://www.efxnow.com/tradetdc5.asp" marginwidth="0" marginheight="0" height="50" width="50" scrolling="no" border="0" frameborder="1"></iframe>
<script language="JavaScript" type="text/javascript">
<!--
var rate=fxrates.document.body.innerHTML;
document.write (rate);
//-->
</script>
</body>
</html>
PeejAvery
March 5th, 2006, 05:36 PM
Along the same lines of this topic....
Unless it is a reply to the first topic, please do not post your problem over someone else's. I will ask Dr. Script to move this to a new thread.
You realize that the you will not get the ASP source of the sight you are trying to see right? Try removing the .body part and just use...
var rate = fxrates.document.innerHTML;
I am not sure but because you are trying to read HTML source of a page on a different web server, you may not be able to accomplish this task due to server security.
bigBA
March 6th, 2006, 08:02 AM
well, as peejavery pointed out, if you are getting an error like "permission denied" than this is because the page holding the iframe comes from another domain than the iframe contents.
if both comes from the same domain your approach shouldn't be a problem.
what else you could do, if you have access to the page you are querying in the iframe, let this page output some javascript which triggers another javascript function in the top frame.
iframe
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>IFrame Page</title>
<meta http-equiv="content-type" content="text/xml;charset=ISO-8859-1" />
<script type="text/javascript">
function triggerParent() {
if( top != self ) {
try {
top.triggerFromFrame( /* here comes the return value of the iframe, maybe a ready-to-use js object */ );
} catch(e) {
//do nothing
}
}
}
triggerParent();
</script>
</head>
<body></body>
</html>
and the top frame only has to define the triggerFromFrame function and wait for it to be called.
bigBA
March 6th, 2006, 08:06 AM
besides this works in both IE and FF:
var sFrameSrc = window.frames['theIFrame'].document.body.innerHTML
well, if name and id of the iframe is set to "theIFrame".
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.