deepak
deepak

Reputation: 105

use of iframe ajax in android browser

I have a html page which is used in a android application . From this page i need to post data to server and response is an attachment which needs to be downloaded. I used the hidden iframe hack for this purpose. But unfortunately its failing. Can anyone explain the root cause?




function download(){

    var iframe = document.createElement("iframe");
    //iframe.src = "http://localhost:9080/HttpOptions/MultiPartServlet";
    iframe.style.display = "none";  
    iframe.id = "myframe";
    document.body.appendChild(iframe);

    var doc = document.getElementById("myframe").contentWindow.document;

    var form = doc.createElement("form"); 
    form.setAttribute("name", "theForm"); // give form a name
    form.setAttribute("id", "theForm"); // give form a name
    form.setAttribute("action", "http://localhost:9080/HttpOptions/MultiPartServlet"); // give form an action
    form.setAttribute("method", "post"); // give form a method

    var par1 = doc.createElement("input");
    par1.setAttribute("name", "theSubmit"); // give input a name
    par1.setAttribute("type", "submit"); // make it a submit button
    par1.setAttribute("value", "Submit"); // give input a value


    var par2 = doc.createElement("input");
    par2.setAttribute("name", "name"); // give input a name
    par2.setAttribute("type", "text"); // make it a submit button
    par2.setAttribute("value", "deepak"); // give input a value

    form.appendChild(par1);
    form.appendChild(par2);

    doc.body.appendChild(form);
    var myframe = document.getElementById('myframe');
    var innerDoc = iframe.contentDocument || iframe.contentWindow.document;

    form.submit();







}





Upvotes: 0

Views: 463

Answers (1)

Raptor
Raptor

Reputation: 54258

Set the document.domain to same value in both parent page and framed page.

Example:

<script type="text/javascript">
document.domain = 'example.com';
</script>

Put this in both parent page and framed page, and the problem will be gone.

Upvotes: 0

Related Questions