var temp_form = document.createElement('form')
var temp_ifr = document.createElement('iframe')
// 设置form属性
temp_form.action = url + '&scope=' + scope
temp_form.target = 'form_iframe'
temp_form.method = 'post'
temp_form.style.display = 'none'
temp_ifr.id = 'id_iframe'
temp_ifr.name = 'form_iframe'
temp_ifr.style.display = 'none'
document.body.appendChild(temp_form)
document.body.appendChild(temp_ifr)
temp_form.submit() // 向iframe中跳 这里已经被隐藏了
document.body.removeChild(temp_form)
document.body.removeChild(temp_ifr)
form提交表单(下载)且不跳转
最新推荐文章于 2022-06-08 10:58:50 发布
本文介绍了一种使用 JavaScript 动态创建 form 和 iframe 实现跨域 POST 提交数据的方法。通过设置 form 的 action、method 和 target 属性,并将目标 iframe 作为提交的目标,可以实现页面之间的数据传递,同时保持操作的隐蔽性。
1203

被折叠的 条评论
为什么被折叠?



