方法一:需引用JQUERY来实现
//初始化默认新窗口配置
var windowDefaultConfig = new Object;
windowDefaultConfig['directories'] = 'no';
windowDefaultConfig['location'] = 'no';
windowDefaultConfig['menubar'] = 'no';
windowDefaultConfig['resizable'] = 'yes';
windowDefaultConfig['scrollbars'] = 'yes';
windowDefaultConfig['status'] = 'no';
windowDefaultConfig['toolbar'] = 'no';
/** 实现函数方便公共调用。
* 以POST表单方式打开新窗口的JQUERY实现
@param:url 需要打开的URL
@param:args URL的参数,数据类型为object
@param:name 打开URL窗口的名字,如果同一按钮需要重复地打开新窗口,
而不是在第一次打开的窗口做刷新,此参数应每次不同
@param:windowParam 新打开窗口的参数配置
* @author: haijiang.mo
*/
function jQueryOpenPostWindow(url,args,name,windowParam){
//创建表单对象
var _form = $("<form></form>",{
'id':'tempForm',
'method':'post',
'action':url,
'target':name,
'style':'display:none'
}).appendTo($("body"));
//将隐藏域加入表单
for(var i in args){
_form.append($("<input>",{'type':'hidden','name':i,'value':args}));
}
//克隆窗口参数对象
var windowConfig = clone(windowDefaultConfig);
//配置窗口
for(var i in windowParam){
windowConfig = windowParam;
}
//窗口配置字符串
var windowConfigStr = "";
for(var i in windowConfig){
windowConfigStr += i+"="+windowConfig+",";
}
//绑定提交触发事件
_form.bind('submit',function(){
window.open("about:blank",name,windowConfigStr);
});
//触发提交事件
_form.trigger("submit");
//表单删除
_form.remove();
}
方法二:在demo.wh.ac.cn案例的buy.js中实现
//data为地址栏?后的传递参数
//name为新弹出的窗口名
function openPostWindow(url, data, name)
{
var tempForm = document.createElement("form");
tempForm.id="tempForm1";
tempForm.method="post";
tempForm.action=url;
tempForm.target=name;
if(data!=""){
inputs=data.split('&');
for(var i=0; i<inputs.length;i++){
var ins=inputs.split('=');
var hideInput = document.createElement("input");
hideInput.type="hidden";
hideInput.name= ins[0];
hideInput.value= ins[1];
tempForm.appendChild(hideInput);
}
}
tempForm.addEventListener("onsubmit",function(){ openWindow(name); });
document.body.appendChild(tempForm);
///fireEvent兼容IE,Chrome,Fire
if (document.createEvent) { // DOM Level 2 standard
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("submit", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
tempForm.dispatchEvent(evt);
} else if (tempForm.fireEvent) { // IE
tempForm.fireEvent('onsubmit');
}
///
tempForm.submit();
document.body.removeChild(tempForm);
}
function openWindow(name){
window.open('about:blank',name,'height=400, width=400, top=0, left=0, toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=yes, status=yes');
}
方法三:构造HTML页面实现
<script language="javascript">
function openWindowWithPost(url,name,keys,values)
{
var newWindow = window.open(url, name);
if (!newWindow)
return false;
var html = "";
html += "<html><head></head><body><form id='formid' method='post' action='" + url + "'>";
if (keys && values)
{
html += "<input type='hidden' name='" + keys + "' value='" + values + "'/>";
}
html += "</form><script type='text/javascript'>document.getElementById('formid').submit();";
html += "<\/script></body></html>".toString().replace(/^.+?\*|\\(?=\/)|\*.+?$/gi, "");
newWindow.document.write(html);
return newWindow;
}
</script>
|