Post a Form to Popup window not to the parent(将表单发布到弹出窗口而不是父级)
问题描述
我想发布一个表单弹出窗口.问题是,表单成功发布,但它也在父窗口上发布.我只想在弹出窗口中提交表单
I want to post a forma poupup window. Problem is, the form posts successfully but It also posts on the parent window. I want to submit the formonly in popup window
'<input type= button value ="Submit Form" onclick="adNetworkForm()" >
<script>
function adNetworkForm(){
targetUrl = "http://somesite.com"
var myForm = document.createElement('form');
myForm.method = 'post';
//myForm.action = targetUrl;
var inpt1 = document.createElement('input');
inpt1.setAttribute('name','a');
inpt1.setAttribute('type', 'hidden')
inpt1.value = "1";
var inpt2 = document.createElement('input');
inpt2.setAttribute('name','b');
inpt2.setAttribute('type', 'hidden')
inpt2.value = 2;
myForm.appendChild(inpt1);
myForm.appendChild(inpt2);
document.body.appendChild(myForm);
myForm.submit(popitup(targetUrl));
document.body.removeChild(myForm);
}
function popitup(url) {
newwindow=window.open(url,'name','height=600,width=500');
if (window.focus) {newwindow.focus()}
return false;
}
</script>'
JS 小提琴
推荐答案
您可以为表单分配一个 onsubmit 事件处理程序以调用一个函数,该函数在提交表单时弹出一个新窗口并将表单定位到该窗口,喜欢:
You could assign an onsubmit event handler to the form to call a function which pops open a new window when the form is submitted and targets the form to that window, like:
<form action="..." method="post" onsubmit="some_popup_post(this);">
<!-- form fields etc here -->
</form>
而 js 代码是:
function some_popup_post(form) {
window.open('', 'formpopup', 'width=400,height=400,resizeable,scrollbars');
form.target = 'formpopup';
}
你的意思是这样的吗..
Do you mean something like this..
这篇关于将表单发布到弹出窗口而不是父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将表单发布到弹出窗口而不是父级


- addEventListener 在 IE 11 中不起作用 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 400或500级别的HTTP响应 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01