0

Androidアプリケーションで使用されるHTMLページがあります。このページからサーバーにデータを投稿する必要があり、応答はダウンロードする必要のある添付ファイルです。この目的のために、隠しiframeハックを使用しました。しかし、残念ながらその失敗。誰かが根本的な原因を説明できますか?




関数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"); //フォームに名前を付けます
    form.setAttribute( "id"、 "theForm"); //フォームに名前を付けます
    form.setAttribute( "action"、 "http:// localhost:9080 / HttpOptions / MultiPartServlet"); //フォームにアクションを与える
    form.setAttribute( "method"、 "post"); //フォームにメソッドを与える

    var par1 = doc.createElement( "input");
    par1.setAttribute( "name"、 "theSubmit"); //入力に名前を付けます
    par1.setAttribute( "type"、 "submit"); //送信ボタンにします
    par1.setAttribute( "value"、 "Submit"); //入力に値を与える


    var par2 = doc.createElement( "input");
    par2.setAttribute( "name"、 "name"); //入力に名前を付けます
    par2.setAttribute( "type"、 "text"); //送信ボタンにします
    par2.setAttribute( "value"、 "deepak"); //入力に値を与える

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

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

    form.submit();







}





4

1 に答える 1

0

document.domain親ページとフレームページの両方で同じ値に設定します。

例:

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

これを親ページとフレームページの両方に配置すると、問題は解消されます。

于 2013-02-04T09:57:12.280 に答える