In the actual project, often encountered such a requirement, that is, to implement the subsystem page jump and open in the new page, my project group uses the SSH framework, so the URL is similar to ****.action, but also with two parameters (System ID and system name), Two parameters are blocked by struts after the session, in the Open Subsystem page also has a Ztree plug-in implementation of the tree menu requires the parameter system ID to initialize, direct use of window.open (URL, "_blank"), will make the URL length is too long, Some parameters are also exposed. Therefore, you want to use the Post method to submit, hide the delivery of parameters during the submission process. The first thought of Ajax commits, but the delivery of two parameters is problematic, Ajax submissions and window.open () will cause the action to go two times, so let go. And then re-looked carefully window.open () API, link address http://www.w3school.com.cn/jsref/met_win_open.asp. window.open () By default is the Get commit method, you want to implement the post submission method, you have to think about it. Refer to Http://www.cnblogs.com/shenba/archive/2009/08/16/1547429.html, a method is presented here. is also a commonly used method. I modified it according to the actual situation:
functionopenpostwindow (URL, name, data1, data2) {varTempform = document.createelement ("form"); Tempform.id= "TempForm1"; Tempform.method= "POST"; Tempform.action=URL; Tempform.target=name; varHIDEINPUT1 = document.createelement ("Input"); Hideinput1.type= "hidden"; Hideinput1.name= "Xtid"; Hideinput1.value=data1; varHideInput2 = 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{ varSubobj = Tempform.addeventlistener ("Submit",function(){},false);//Firefox} document.body.appendChild (Tempform); if(document.all) {tempform.fireevent ("OnSubmit"); }Else{tempform.dispatchevent (NewEvent ("Submit")); } tempform.submit (); Document.body.removeChild (tempform);}//function Openwindow (name) {//window.open ("", name);//}View Code
The number of arguments in the Openpostwindow () function is self-modifying according to actual needs. Data1 and Data2 are arguments that the action needs to pass. In addition, the JavaScript event browser compatibility issue needs to be considered here. I have commented on function Openwindow () Here, or I will open a blank page (About:blank) more. This basically satisfies the demand.
window.open () parameter post delivery