...

View Full Version : Get content of iframe



Yorick
10-23-2006, 10:40 AM
Ok guys, I'm stuck at something I'm working on, I wan't to upload a image to my other server, and then return the link to that image to use it.

So i've already made te following:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Hello!</title>
<script type="text/javascript">
function uploadform()
{
alert(document.getElementById('target_upload').innerHTML);
document.getElementById('text').innerHTML = document.getElementById('target_upload').innerHTML;
}
</script>
</head>


<body>

<iframe onload="uploadform();" id='target_upload' name='target_upload' src='' style='width:500px;height:150px;border:1'></iframe>

<form action="http://server2.com/index.php" name="upload" action="" method="POST" enctype="multipart/form-data" target="target_upload">
<input name="fileupload" type="file" size="30" />
<input type="button" name="test" value="test" onclick="uploadform();" />
<input type="submit" name="submit" value="Submit" />

</form>
<span id="text">
</span>

</body>

</html>

As you see I wan't to get the contents of the iframe to rip out the link to the image (my other server returns a XML information feed about the uploaded file). But whatever I try I keep getting back a empty innerHTML of the iframe, and because of that also an empty alert.

What am I doing wrong?

Thanks in advcane!

mrhoo
10-24-2006, 06:48 AM
Two things-
1. If the iframe src is on a different domain or server than the page that
contains it, you cannot read any of the src document's properties with
javascript.

2. document.getElementById('target_upload').innerHTML contains what is in the iframe tag only-

if you are on the same origin you get to the document in the iframe with
var D=document.getElementById('target_upload').contentWindow.document
Then use D.documentElement.innerHTML or D.body.innerHTML to return the source code from the document in the iframe

Yorick
10-25-2006, 12:02 AM
Two things-
1. If the iframe src is on a different domain or server than the page that
contains it, you cannot read any of the src document's properties with
javascript.


Is there a work around for this?

And if I use document.getElementById('target_upload').contentWindow.document it returns [object], target_upload.document.body.innerHTML works good...

A1ien51
10-25-2006, 12:57 PM
No there is no work around since it is a security feature protecting your privacy as a surfer. You need to use a server with a proxy.

Eric

damtrojan
04-29-2007, 04:58 PM
Might be too old, but you can use a scripting language such as php, CF, or ASP on a local page to get a foreign site and output it file_get_contents, cfhttp, and I forget the asp command.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum