将表单发布到弹出窗口而不是父窗口 [英] Post a Form to Popup window not to the parent
本文介绍了将表单发布到弹出窗口而不是父窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想发布一个forma poupup窗口。问题是,表单成功发布,但它也发布在父窗口上。我想在弹出窗口中提交formonly
'< input type = button value =提交表单onclick =adNetworkForm ()>
< script>
函数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);
}
函数popitup(url){
newwindow = window.open(url,'name','height = 600,width = 500');
if(window.focus){newwindow.focus()}
return false;
}
< / script>'
< a href =http://jsfiddle.net/7Eusb/ =nofollow> JS Fiddle p>您可以将一个onsubmit事件处理程序分配给窗体来调用一个函数,当窗体被提交时它会弹出一个新窗口并将窗体定位到该窗口中,如:
< form action =...method =postonsubmit =some_popup_post(this);>
<! - 表单字段等在这里 - >
< / form>
而js代码是:
function some_popup_post(form){
window.open('','formpopup','width = 400,height = 400,resizeable,scrollbars');
form.target ='formpopup';
}
你的意思是这样的..
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>'
解决方案
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>
And js code would be:
function some_popup_post(form) {
window.open('', 'formpopup', 'width=400,height=400,resizeable,scrollbars');
form.target = 'formpopup';
}
Do you mean something like this..
这篇关于将表单发布到弹出窗口而不是父窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文