Alert box after 5 seconds and close window

Hi,

I need an alert box to pop up after 5 seconds with a button that says 'Complete'.   When the button is closed, it should close the window (which is a pop up window).
I am doing this after a money transaction so that the window will close and cannot be tampered with =)  Not to annoy users.

Thanks!
JuniorBeeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gksinghietCommented:
With alert box you cannot have your customized buttons.
Still if you want to close the window after showing alert use this:
<html>
<head>
 <title>JavaScript Window Close Example </title>
</head>
<script language="JavaScript">
function popuponclick()
{
  my_window = window.open("",  "mywindow","status=1,width=350,height=150");
  my_window.document.write('<H1>The Popup Window</H1>');  
}

function closepopup()
{
   if(false == my_window.closed)
   {
     alert("Your message");
     my_window.close ();
   }
   else
   {
     alert('Window already closed!');
   }
}
</script>
<body>
<P>
<A href="javascript: popuponclick()">Open Popup Window</A>
</P>
<P>
<A href="javascript: closepopup()">Close the Popup Window</A>
</P>
</body>
</html>
0
gksinghietCommented:
Another way of doing this without using alert box is:
<html>
<head>
 <title>JavaScript Window Close Example </title>
</head>
<script language="JavaScript">
function popuponclick()
{
  my_window = window.open("",  "mywindow","status=1,width=350,height=150");
  my_window.document.write('<H1>The Popup Window</H1>');  
}

function closepopup()
{
   if(false == my_window.closed)
   {
     my_window.close ();
   }
   else
   {
     alert('Window already closed!');
   }
}

function ignore() {
  alert("Canceled closing the popup window");
}

function showConfirmationBox() {
  var confirmationBox = document.getElementById("ConfirmationBox");
  confirmationBox.style.display = "";
}
</script>
<body>
<P>
<input type="button" value="OpenPopupWindow" onclick="popuponclick();"/>
</P>
<P>
<input type="button" value="ClosePopupWindow" onclick="setTimeout('showConfirmationBox();', 5000);"/>
</P>
<div id="ConfirmationBox" style="display:none;">
  <p>Do you want to close the popup window<p>
  <input type="button" value="Yes" onclick="javascript: closepopup()"/>
  <input type="button" value="No" onclick="javascript: ignore()"/>
<div>
</body>
</html>
0
Michel PlungjanIT ExpertCommented:
gksinghiet : you probably want to change
function popuponclick()
{
  my_window = window.open("",  "mywindow","status=1,width=350,height=150");
  my_window.document.write('<H1>The Popup Window</H1>');  
}

function closepopup()
{
   if(false == my_window.closed)
to

my_window = null; // make a global var
function popuponclick()
{
  my_window = window.open("",  "mywindow","status=1,width=350,height=150");
  my_window.document.write('<H1>The Popup Window</H1>');  
  my_window.document.close();// finalise the window
}

function closepopup()
{
   if(my_window && !my_window.closed)

Michel
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

JuniorBeeAuthor Commented:
OK, I do not want a link that opens the alert box, it should open on its own after 5 seconds.  All the examples you have provided don't do this.  :(
0
JuniorBeeAuthor Commented:
ok, I used this:

<script>alert('Message goes here');window.close();</script>

and it works great.  Have any idea how to make it come up after 5 seconds instead of immediately?
0
almesCommented:

Use :

<script>window.setTimeout('alert("Message goes here");window.close();', 5000);</script>

almes
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nabsolCommented:
Hi

Use this :

<html>
<head>

<script>
[*** window hack removed by ee page editor ***]
window.setTimeout('alert("Message goes here");window.close();', 5000);
</script>

</head>

<body cursor: url(a.cur) , auto;>
<form name="abc">
<input type="text" name="country">
</form>
</body>
</html>

By Nab
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.