首页 文章

在android浏览器中使用iframe ajax

提问于
浏览
0

我有一个在Android应用程序中使用的html页面 . 从这个页面我需要将数据发布到服务器,响应是需要下载的附件 . 我为此目的使用了隐藏的iframe hack . 但不幸的是它失败了 . 任何人都可以解释根本原因吗?

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();







}

1 回答

  • 0

    在父页面和框架页面中将 document.domain 设置为相同的值 .

    例:

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

    把它放在父页面和框架页面中,问题就会消失 .

相关问题