JS simulation Form form submission data, JS analog a tag Click Jump, avoid the browser blocking problem with window.open
JS simulation Form form submission Data source:
/** * JS Simulation Form form Submission * @param {Object} Parameter Object * URL required submit address * Methond optional default Post submission method Post get* target Select the default _self current page or new page _self _blank* Other parameters */function Jsformsubmit (params) { var turnform = document.createelement ("form"); Be sure to join the body!! Document.body.appendChild (turnform); var method = params[' Methond ' | | "POST";//The default is post Turnform.method = method; Delete params[' Methond ']; var target = params[' target ' | | "_self";//defaults to the current page turnform.target = target; Delete params[' target ']; var url = params.url; Submit address turnform.action = URL; Delete params[' url ']; Create a hidden form for (var item in params) { var newelement = document.createelement ("input"); Newelement.setattribute ("type", "hidden"); Newelement.setattribute ("name", item); Newelement.setattribute ("value", Params[item]); Turnform.appendchild (newelement); } Turnform.submit ();}
JS simulation Form form submission using example:
var params = { //required parameter "url": URL, "Methond": "Post", "target": "_blank", //Below is the data to be submitted "J_ Username ":" SYNKMXS0000000043 ", " J_password ":" 3258 "} formsubmit (params);
JS analog a Click Source:
/** * JS Analog a click * @param {string} URL required to submit address * @param {string} target optional default _self Current page or new page _self _blank*/function jsalink (url,target) { var target = target | | "_blank"; First read ALink does not exist then create var ALink = document.getElementById ("ALink"); if (alink==undefined) alink=document.createelement ("a"); Assignment alink.id = "ALink"; alink.href = URL; Alink.target = target; Alink.style = "display:none;"; Write page document.body.appendChild (ALink); Perform a click event document.getElementById ("ALink"). Click ();
JS analog A click Example:
Jsalink ("http://www.jsfun.cn", "_blank");
Source: jsfun.cn
JS simulation Form form submission data, JS analog a tag Click Jump, avoid the browser blocking problem with window.open