Javascript弹出窗口:提交表单,显示"wait"屏幕持续5秒钟,然后自动关闭弹出窗口 [英] Javascript popups: Submit form, show "wait" screen for 5 seconds, then auto-close popup

查看:387
本文介绍了Javascript弹出窗口:提交表单,显示"wait"屏幕持续5秒钟,然后自动关闭弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个弹出窗口,要求用户填写表格.提交表单后,我需要在检查其信息时将其带到同一弹出窗口中的等待"屏幕.这是一个原型,因此仅需要大约5秒钟的延迟,因为实际上没有检查任何内容.然后,我想在该延迟之后自动关闭弹出窗口,而不是使用附加到按钮的window.close();.

I have a popup that requires the user to fill out a form. Once the form is submitted, I need to take them to a "Waiting" screen inside that same popup while their info is checked. This is a prototype, so it only needs a delay of about 5 seconds as nothing is actually being checked. Then I'd like to close the popup automatically after that delay, instead of using window.close(); attached to a button.

这是我正在使用的脚本:(已编辑以删除内联js)

Here's the script I'm using: (edited to remove inline js)

function centeredPopup(url,winName,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
popupWindow = window.open(url,winName,settings)
}

$('#linkPopup').click(function(){
    $(this).click(centeredPopup("popup.php","Popup Name","680","560"));

    if(window.location.href=='popup_waiting.php'){
        setTimeout(function() {
        close.window();
        }, 5000);
    }   
});

我如何触发弹出窗口:

<a class="button" id="linkPopup">Popup Link</a>

使用上面的代码,该表单仅提交到等待屏幕,但在指定的持续时间后没有关闭,因此我假设我的语法或结构有问题.

Using my code above, the form just submits to the waiting screen but doesn't close it out after the specified duration, so I'm assuming there's something wrong with my syntax or structure.

预期行为:

推荐答案

我通过在等待页面弹出窗口中添加以下内容来解决了这个问题:

I solved this by including the following into the waiting page popup:

<script type="text/javascript">
$(document).ready(function() {
setTimeout(function(){ 
    window.opener.location.href = "parentpage.php";
    window.close();
}, 2000); 
});
</script>

可以解决问题.

这篇关于Javascript弹出窗口:提交表单,显示"wait"屏幕持续5秒钟,然后自动关闭弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆