window.open post传参


In fact I made a small "library" just for this, open in POST a new window : // Arguments : // verb : 'GET'|'POST' // target : an optional opening target (a name, or "_blank"), defaults to "_self" open = function(verb, url, data, target) { var form = document.createElement("form"); form.action = url; form.method = verb; form.target = target || "_self"; if (data) { for (var key in data) { var input = document.createElement("textarea"); input.name = key; input.value = typeof data[key] === "object" ? JSON.stringify(data[key]) : data[key]; form.appendChild(input); } } form.style.display = 'none'; document.body.appendChild(form); form.submit();

//最好 remove 掉 form
  document.body.removeChild(form);
}; Example : open('POST', 'fileServer.jsp', {request: {key:"42", cols:[2, 3, 34]}}); To open in a new window, set the target parameter : open('POST', someURL, someArgs, 'newwin'); or to ensure it's a new window/tab each time : open('POST', someURL, someArgs, '_blank'); Obviously you should give it a name other than open so that you don't shadow the existing one. Ideally you should namespace it.

原文地址:https://stackoverflow.com/questions/17793183/how-to-replace-window-open-with-a-post

posted on 2019-04-24 11:05  ZhYQ_note  阅读(384)  评论(0)    收藏  举报

导航