In actual projects, I often encounter such a requirement, that is, to jump between subsystem pages and open on a new page. The project team I am in is using an SSH framework, so the urls are similar to ****.action, and they also have two parameters (system ID and system name). The two parameters are intercepted by struts and stored in the session. There is also a tree-like menu implemented by the ztree plug-in in the open subsystem page that requires the parameter system ID to be initialized. Use window.open(url,"_blank") directly, which will make the url too long and also expose some parameters. Therefore, I want to use post to submit instead, hiding the passing of parameters during the submission process. First of all, I think of ajax submission, but there will be problems with the passing of two parameters. Ajax submission and window.open() will cause the action to go twice, so I will give it up. Later, I carefully looked at the window.open() API again, and the link address was http://www.w3school.com.cn/jsref/met_win_open.asp. window.open() is the get submission method by default. If you want to implement the post submission method, you have to think of another method. Refer to //www.VeVB.COM/article/32826.htm, a method is introduced here. It is also a method that is often used. I made some modifications based on the actual situation:
The code copy is as follows:
function openPostWindow(url, name, data1, data2){
var tempForm = document.createElement("form");
tempForm.id = "tempForm1";
tempForm.method = "post";
tempForm.action = url;
tempForm.target=name;
var hideInput1 = document.createElement("input");
hideInput1.type = "hidden";
hideInput1.name="xtid";
hideInput1.value = data1;
var hideInput2 = document.createElement("input");
hideInput2.type = "hidden";
hideInput2.name="xtmc";
hideInput2.value = data2;
tempForm.appendChild(hideInput1);
tempForm.appendChild(hideInput2);
if(document.all){
tempForm.attachEvent("onsubmit",function(){}); //IE
}else{
var subObj = 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);
}
//function openWindow(name){
// window.open("",name);
//}
The number of parameters in the openPostWindow() function is modified by itself according to actual needs. data1 and data2 are the parameters that need to be passed in action. In addition, Javascript event browser compatibility issues need to be considered here. I have commented on function openWindow() here, otherwise I will open an extra blank page (about:blank). This basically meets the needs.
The above is all the content shared in this article, I hope you like it.