function openPostWindow(url, data, name) {
var tempForm = document.createElement("form");
tempForm.id="tempForm1";
tempForm.method="post";
//url
tempForm.action=url;
//open方法不能设置请求方式,一般网页的post都是通过form来实现的。
//如果仅仅模拟form的提交方式,那么open方法里那种可设置窗体属性的参数又不能用。
//最后想办法整了这么一个两者结合的方式,将form的target设置成和open的name参数一样的值,通过浏览器自动识别实现了将内容post到新窗口中
tempForm.target=name;
var hideInput = document.createElement("input");
hideInput.type="hidden";
//传入参数名,相当于get请求中的content=
hideInput.name= "atKmInfo.infoText";
//传入传入数据,只传递了一个参数内容,实际可传递多个。
hideInput.value= data;
tempForm.appendChild(hideInput);
document.body.appendChild(tempForm);
tempForm.submit(openWindow(name));
document.body.removeChild(tempForm);
}
function openWindow(name) {
var width = 1000;
var height = 600;
var left = parseInt((screen.availWidth/2) - (width/2));
//屏幕居中
var top = parseInt((screen.availHeight/2) - (height/2));
var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
window.open(''
,name,windowFeatures);
}
form表单提交,并打开新窗口解决方法之一
猜你喜欢
转载自1124258326.iteye.com/blog/2353481
今日推荐
周排行