Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7160
  • Last Modified:

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!
0
JuniorBee
Asked:
JuniorBee
1 Solution
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now