Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get content of iframe

    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:

    Code:
    <!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!

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    728
    Thanks
    35
    Thanked 132 Times in 123 Posts
    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
    Last edited by mrhoo; 10-25-2006 at 03:16 PM.

  • #3
    New Coder
    Join Date
    Apr 2005
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mrhoo View Post
    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...
    Last edited by Yorick; 10-25-2006 at 01:05 AM.

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    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
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #5
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    It is acually possible

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •