Have a custom popup Alert mimic a windows alerts

I have custom alert popup made with a div.  There are certain points within my code such as when the user will get logged off of the server after a certain amount of time.  When this happens an Alert popups to inform the user that the session has expired and then once you click ok will bring you back to the login screen.  With the current code using the div it pops up and then proceeds to do then re-directing code.

I know you can't halt the code.  No points for stating the obvious.  I need a work-around method.  I've been trying some ideas using setTimeout to recheck whether or not the div is still visible to no avail.  Any help would be great, thanks!
LVL 6
dgelinasAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

jaysolomonCommented:
so you want to check if the div is hiiden or visible?

is this correct?
dgelinasAuthor Commented:
Yes I'm going to be checking if it is visible or hidden.  

But I need the code to loop checking for whether or not it is hidden and once it is then have it continue from there.  
fritz_the_blankCommented:
I would do the following:

Any time the div visibility is toggle to visible, set a global variable, bolVisible, to true. When it is toggled to invisible, set the variable to false. Then you only need check the value of the variable.

FtB
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

fritz_the_blankCommented:
The other possibility is to use the onLoad() method of the page where the redirect takes place to spawn a new pop up.

That way, you don't have to worry about whether it is visible, closed, and etc.

Fritz the Blank

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
jaysolomonCommented:
i may be lost but can you not do this

if(document.getElementById('alertDIV').style.visibility == 'visible'){
     // Do What you want because it is visible
}
else {
       // Do what you need to since its hidden
}
fritz_the_blankCommented:
If your browser is recent enough, and the window isn't closed, then that should do it as well.

FtB
dgelinasAuthor Commented:
heh must be lost.. I'm looking to something like this

  function WaitForClose () {                  
    if ( alertBox.visibility=="visible" )    
      setTimeout ( WaitForClose, 500 );
        else
          alertVisible = false;             
  }

dgelinasAuthor Commented:
Fritz I can narrow it down and modify code in each situation(too much code), but I'd rather be able to just have it loop like I posted above. thanks for trying though
fritz_the_blankCommented:
alertBox.style.visibility=="visible"

FtB
dgelinasAuthor Commented:
whoops, here it is rather, forgot the style.  Anyone see why this wouldn't halt?

 function WaitForClose () {                  
    if ( alertBox.style.visibility=="visible" )    
      setTimeout ( WaitForClose, 500 );
        else
          alertVisible = false;            
  }
fritz_the_blankCommented:
Also, I may be mistaken, but you might have to put your function name in delimiters:

setTimeout ( 'WaitForClose()', 500 );
fritz_the_blankCommented:
So, putting it together:

 function WaitForClose () {                  
    if ( alertBox.style.visibility=="visible" )    
      setTimeout ( "WaitForClose", 500 );
        else
          alertVisible = false;            
  }
jaysolomonCommented:
function WaitForClose () {                  
    if (document.getElementById('alertBox').visibility=="visible" )    
      setTimeout ("WaitForClose()", 500 );
        else
          document.getElementById('alertBox').visibility= "hidden"            
  }
fritz_the_blankCommented:
Hah! Beat you by 2 milliseconds!

FtB
jaysolomonCommented:
you need to give your alert div a id and name it "alertBox"

<div id="alertBox">
jaysolomonCommented:
took me 2ms to type document.getElementById
dgelinasAuthor Commented:
Thanks but the reason why the code I pasted wasn't perfect is because I didn't paste it from what I was using, I typed it out because that is generally the basic idea of what I'm trying to do..

The code the way it is gives memory errors, because it puts itself in an infinite loop.  There is a button found on the Div that once clicked will make it hidden, which will then effect the condition.  Problem is that as soon as this code is run it gives me memory errors.
 
Even though I have it run itself after a specified time and check a condition it doesn't seem to be working that way I have set it to work.  
 

jaysolomonCommented:
can you show us a link or posted the ORIGINAL code

basically all we are doing is playing a guessing game, with one script to try and make another work.

If you will post the code your having problems with, we may be able to help you get rid of the meomry leak/problem
fritz_the_blankCommented:
The basic premise is fine:

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
var intCounter = 0

function showCounter(){
       if(intCounter<5){
            intCounter++;
            alert(intCounter);
            setTimeout("showCounter()",3000);
      }
}
//-->
</SCRIPT>

</HEAD>
<BODY onLoad=showCounter()>

<P>&nbsp;</P>

</BODY>
</HTML>

FtB
Oliver_DornaufCommented:
For me it seems you should solve the problem on your server not on the client side
fritz_the_blankCommented:
Again, I would spawn the popup with the onLoad of the window from the redirect. That way, you have tighter control.

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