在禁用调整大小的情况下向弹出窗口提交HTML表单,可以通过以下方法实现:
var myWindow = window.open("", "", "width=500, height=400, resizable=no");
<form id="myForm">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br>
<input type="submit" value="Submit">
</form>
document.getElementById("myForm").addEventListener("submit", function(event){
event.preventDefault();
var xhr = new XMLHttpRequest();
xhr.open("POST", "your-server-url-here", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
alert("Form submitted successfully!");
myWindow.close();
}
};
var formData = new FormData(event.target);
xhr.send(formData);
});
这样,在用户提交表单后,弹出窗口将关闭,并通过AJAX将表单数据发送到服务器。同时,由于窗口大小不可调整,用户无法更改窗口大小。
领取专属 10元无门槛券
手把手带您无忧上云