Using this rule, open a blank window with the specified title in the current window, and then submit the virtual form to the window corresponding to the title.
1. The wallimn-util.js file. A separate general js file, put many general functions
/** * JS submits data via POST via virtual form * @param URL * @param PARAMS * @returns */ function jsPost(URL, PARAMS, TARGET) { var temp = document.createElement("form"); temp.action = URL; temp.method = "post"; temp.style.display = "none"; if(!TARGET){ TARGET="_self"; } temp.target=TARGET; for (var x in PARAMS) { var opt = document.createElement("textarea"); opt.name = x; opt.value = PARAMS[x]; temp.appendChild(opt); } document.body.appendChild(temp); temp.submit(); return temp; }
2. The page that needs to open the window with javascript:
//Some people say that this function needs to be called through the onclick of a. I haven't tested the button to see if it works. //If you want to put window.open not on the current page and write it in the wallimn-util.js file above, the browser will also block it. function jsOpenWin(){ var title="js new window"; window.open("about:blank",title); jsPost("wallimn.iteye.com",{name:"wallimn"},title); }
3. Important note:
window.open can only be written in the current page.
window.open can only be written in the current page.
window.open can only be written in the current page.