提交form方式打开新页面,可以跨域提交参数,而且打开新页面不会被浏览器拦截
// 打开新窗口 // postNew('http://localhost:8080',{name:'小明',age:12}) function postNew(url, params) { let form = document.createElement('form'); form.method = 'get'; form.action = url; let formHtml = ''; if (params != "") { Object.keys(params).forEach((key,i) => { let value = params[key]; formHtml += `<input type="hidden" name="${key}" value="${value}" />`; }) form.innerHTML = formHtml; } document.body.insertAdjacentElement('beforeend', form); //target也可以是本页面的iframe的name form.target = '_blank'; form.submit(); }
标签:formHtml,form,新页面,let,提交,params,打开 From: https://www.cnblogs.com/mengff/p/16790843.html