I would like to make a popup window, but when I popup the window, I would like to post some in开发者_JAVA百科formation, how can I do so? Thank you.
You can open the popup within the form's .submit
handler and set the form's target to the popup.
$("#myForm").submit(function(e) {
window.open('', 'popupform', 'width=400,height=400,resizeable,scrollbars');
// target the form to the newly opened popup
this.target = "popupform";
});
Demo.
just
window.open("yoururl.php", "_blank", "width=400,height=500");
and there, in new window, use
$(function(){
$.post('some_post_script.php', {data:'here'}, function(){
alert('post sent');
});
});
If you want to do it through your form, you can use the Form2Pop script by Peter Bailey.
Add this javascript to your page
<script type="text/javascript">
/*
Form2Pop Script- By Peter Bailey (http://www.peterbailey.net)
Featured on JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
*/
function createTarget(t){
window.open("", t, "width=600,height=550");
return true;
}
</script>
And then when you're creating your form
<form action="/someurl" onsubmit="return createWebChat(this.target)" target="popupWindow">
This will POST your form to /someurl and open up the result in a new window. Then you can adjust the pop up window to your liking by editing the window.open().
精彩评论