JS form跳转到新标签页并用post传参-LMLPHP

1 超链接<a>标签  (get传参)

   <a href="http://www.cnblogs.com/pan1042/" target="_blank">

2 window.open()  (get传参)

  window.open(URL,name,specs,replace)

   例: window.open(url + "? param1=value1&param2=value2", "_blank")

3 form  (post传参)

function openPostWindow(url, data, name)
{
var tempForm = document.createElement("form");
tempForm.id = "tempForm1";
tempForm.method = "post";
tempForm.action = url;
tempForm.target = name; // _blank - URL加载到一个新的窗口 var hideInput = document.createElement("input");
hideInput.type = "hidden";
hideInput.name = "content";
hideInput.value = data;
tempForm.appendChild(hideInput);
// 可以传多个参数
/* var nextHideInput = document.createElement("input");
nextHideInput.type = "hidden";
nextHideInput.name = "content";
nextHideInput.value = data;
tempForm.appendChild(nextHideInput); */
if(document.all){ // 兼容不同浏览器
tempForm.attachEvent("onsubmit",function(){}); //IE
}else{
tempForm.addEventListener("submit",function(){},false); //firefox
}
document.body.appendChild(tempForm);
if(document.all){ // 兼容不同浏览器
tempForm.fireEvent("onsubmit");
}else{
tempForm.dispatchEvent(new Event("submit"));
}
tempForm.submit();
document.body.removeChild(tempForm);
}

【参考】

  1. https://www.runoob.com/jsref/met-win-open.html  
  2. https://blog.csdn.net/u013303551/article/details/52909871
05-11 18:21