用window.open时能否通过post方式传输数据?
不能的。Window.open只能用get的方式(附带在url后面)。
那么有别的方法达到类似的效果吗?
有的。
直接构建一个临时form,然后指定form的参数method = post, target=_blank
这样,就既弹出一个新窗口,又可以把数据post过去了。
具体例子:
function exportOrderInfo(){
var tempForm = document.createElement("form");
tempForm.id="tempForm1";
tempForm.method="post";
tempForm.action='这里填url';
tempForm.target='_blank';
var hideInput = document.createElement("input");
hideInput.type="hidden";
hideInput.name= "这里填数据名"
hideInput.value= "这里填数据值";
tempForm.appendChild(hideInput);
tempForm.appendChild(hideInput);
document.body.appendChild(tempForm);
tempForm.submit();
document.body.removeChild(tempForm);
return true;
}
至于其他人介绍的另外一种方法,window.open一个空白窗口,再利用相同的name,把数据post过去。我是没理解为何不直接post。window.open很多时候会被浏览器拦截。
页:
[1]