gpt4 book ai didi

javascript 在提交时关闭弹出窗口

转载 作者:数据小太阳 更新时间:2023-10-29 06:12:29 25 4
gpt4 key购买 nike

好的。我已经看到这个问题已经有 10 多年没有得到解答了。

如何在一个按钮调用中提交和关闭弹出窗口。

建议就这样运行。

function saveNClose()
{
document.form.submit();
self.close();
}
this doesn't work because the submit has a redirect, and the self.close is never reached.

function closeLaterNSaveNow();
{
setTimeout("window.close()",5000);
document.form.submit();
}
same problem.. the close is never called because the script for the page is gone.

function closeNowNSubmit()
{
self.close();
document.form.submit();
}
the window closes, but nothing gets saved. server doesn't even get notified of anything..

<input class='btn btn-success' disabled='disabled' id='SubmitFinal' onclick='closeWindow()' type='submit' value='Finish'>
Well then there's no validation of the data. it submits before the function is called.

有人解决这个问题吗?早在 2002 年,我就发现了相同的解决方案,有些甚至是本月才发现的。我将继续寻找,但我希望有人已经解决了它并且希望有人在这里回答

最佳答案

一个典型的解决方案是输出一个 JS 片段,该片段将在提交后作为结果页面关闭窗口。

<script type="text/javascript">
window.close();
</script>

另一种解决方案是通过 AJAX 提交表单数据,并在请求完成后关闭窗口。您可以使用 jQuery Form plugin为此:

$("#myForm").ajaxForm(function() { 
window.close();
})

关于javascript 在提交时关闭弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14617199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com