Sam Ivichuk
Sam Ivichuk

Reputation: 1028

Can't get iframe content

I know there are many topics about it, but none of them worked. I need just to get iframe content(not source code).

I have a form, that posts some parameters to another server and I target it to iframe(that lies on the same page). So I receive server responce code storred in my iframe without page refresh:

<form name='vin_form' id='file_upload_form' action='*****' method='post'>
    <input name='name1' value='value1'>
    <input name='name2' value='value2' type='hidden'>
    <input name='name3' value='value3' type='hidden'>
    <div onclick=\"document.getElementById('file_upload_form').target = 'upload_target'; document.vin_form.submit();\">Send form</div>
</form>";

<iframe id='upload_target' name='upload_target'></iframe>

To get iframe content I used everything, but nothing worked:

jQuery('#upload_target').load(function()
    {
            alert(jQuery('#upload_target').contents().find('body').html());

            var myIFrame = document.getElementById('upload_target');
            var content = myIFrame.contentWindow.document.body.innerHTML;
            alert(content);

            alert(window.frames.upload_target.document.body);
    }
);

I read about "same origin policy", but I think it shouldn't be forbidden in my case, because I can access that page by url and read all the code, so why I can't do it programmatically?

P.S.: Are there some other ways to get form responce code from another server? (php curl doesn't work because of some site framework defence)

Upvotes: 1

Views: 4541

Answers (1)

Ram
Ram

Reputation: 144659

*update - try this:

 var t = document.getElementById("upload_target");
 var y =( t.contentWindow || t.contentDocument);
 alert(y.document.body.innerHTML)

Upvotes: 1

Related Questions