Javascript Popups: Submit Form, Show & ldquo; wait & rdquo; screen for 5 seconds then the automatic closing

advertisements

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.

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);
    }
});

How I'm firing the popups:

<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.

Expected Behavior:


here's a plunker: http://plnkr.co/edit/EAWf6EPauBuz36Wu8Erk?p=info

first thing's first, consider this answer on why you shouldn't use inline javascript.

in order to open a popup window you could use:
window.open();

window.open(strUrl, strWindowName[, strWindowFeatures]);

after the popup opens, you can close it with
window.close();

you'll need to set a timer, that'll wait 5 seconds and then close the popup

window.setTimeout(func, delay, [param1, param2, ...]);