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 = ""
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 Fiddle
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."
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 Fiddle
Share asked Jun 15, 2012 at 7:06 Muhammad UsmanMuhammad Usman 11k22 gold badges75 silver badges109 bronze badges 1- Possible duplicate of Window.open and pass parameters by post method – Ulad Kasach Commented May 18, 2016 at 19:31
1 Answer
Reset to default 5You 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..
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744927267a4601515.html
评论列表(0条)