js模拟form打开新窗口

1.打开新窗口

function postNew(url, params) {
var form = $("<form method='post'></form>");
var input;
form.attr({ "action": url });
if (params != "") {
$.each(params, function (key, value) {
input = $("<input type='hidden'>");
input.attr({ "name": key });
input.val(value);
form.append(input);
});
}
form.attr({ "target":"_blank" });
$(document.body).append(form);
form.submit();
}

 

/**
* form表单提交本页面打开
* @param url
* @param params
*/
function postCurrent(url, params) {
var form = $("<form method='post'></form>");
var input;
form.attr({ "action": url });
if (params != "") {
$.each(params, function (key, value) {
input = $("<input type='hidden'>");
input.attr({ "name": key });
input.val(value);
form.append(input);
});
}
$(document.body).append(form);
form.submit();
}

 

/**
* form表单提交新打开页面,弹出窗口
* @param url
* @param params
*@windowname
*/
function postNew(url, params, windowname) {
var form = $("<form method='post'></form>");
var input;
form.attr({ "action": url });
if (params != "") {
$.each(params, function (key, value) {
input = $("<input type='hidden'>");
input.attr({ "name": key });
input.val(value);
form.append(input);
});
}
form.attr({ "target": windowname });
window.addEventListener("onsubmit", function () { openWindow(windowname); });
$(document.body).append(form);
window.dispatchEvent(new Event("onsubmit"))
form.submit();
}

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');
}

参数解释:
      window.open 弹出新窗口的命令; 
  'about:blank' 弹出窗口的文件名; 
  name 弹出窗口的名字(不是文件名),非必须,可用空''代替; 
  height=400 窗口高度; 
  width=400 窗口宽度; 
  top=0 窗口距离屏幕上方的象素值; 
  left=0 窗口距离屏幕左侧的象素值; 
  toolbar=no 是否显示工具栏,yes为显示; 
  menubar,scrollbars 表示菜单栏和滚动栏。 
  resizable=no 是否允许改变窗口大小,yes为允许; 
  location=no 是否显示地址栏,yes为允许; 
  status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;

 

//调用
preview()
{
var json = {
'workStatus': workStatus,
'designNums': this.designNums,
'designModel': this.designModel,
'worksType': this.worksInfo.worksType,
'designUserList': JSON.stringify(designUserList),
'promiseImg1': this.promiseImg1,
'promiseImg2': this.promiseImg2,
'promiseImg3': this.promiseImg3,
'promiseImg4': this.promiseImg4,
'worksInfo': JSON.stringify(worksInfo)
};
var postUrl = 'https://www.baidu.com/';
postCurrent(postUrl, json);

}

posted @ 2019-11-28 11:02  阳光下丶  阅读(1093)  评论(0编辑  收藏  举报