我有一个用于 android 应用程序的 html 页面。从这个页面我需要将数据发布到服务器,响应是一个需要下载的附件。为此,我使用了隐藏的 iframe hack。但不幸的是它失败了。谁能解释根本原因?
函数下载(){
var iframe = document.createElement("iframe");
//iframe.src = "http://localhost:9080/HttpOptions/MultiPartServlet";
iframe.style.display = "无";
iframe.id = "我的框架";
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("方法", "post"); // 给表单一个方法
var par1 = doc.createElement("input");
par1.setAttribute("name", "theSubmit"); // 给输入一个名字
par1.setAttribute("类型", "提交"); // 使其成为提交按钮
par1.setAttribute("值", "提交"); // 给输入一个值
var par2 = doc.createElement("input");
par2.setAttribute("name", "name"); // 给输入一个名字
par2.setAttribute("类型", "文本"); // 使其成为提交按钮
par2.setAttribute("值", "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();
}