window.open () parameter post delivery

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.