1

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:

Expected Behavior

bcam7
  • 67
  • 1
  • 9

2 Answers2

0

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, ...]);

Community
  • 1
  • 1
Nitsan Baleli
  • 5,393
  • 3
  • 30
  • 52
  • Thanks for the assistance. What would typically be placed in the two empty strings after `window.open(`? The urls to the relevant popups? I'm already inside a popup with the form, so onSubmit of that form, I need to go to another page inside the popup, then close it after the delay. – bcam7 Jan 28 '14 at 12:33
  • I'm still at a loss here. `$('#linkPopup').click(function(){ $(this).click(centeredPopup("popup.php","Popup Name","680","560")); if(window.location.href=='popup_waiting.php'){ setTimeout(function() { close.window(); }, 5000); } });` I tried this, but it's still not working. The code you provided wasn't working either :/ – bcam7 Jan 28 '14 at 18:57
  • Try reading the documentation in the links, if you have any questions after that, go ahead. – Nitsan Baleli Jan 28 '14 at 19:00
  • @baleinitsan I've updated the post (along with an image) to clarify. – bcam7 Jan 29 '14 at 00:32
0

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>

That does the trick.

bcam7
  • 67
  • 1
  • 9