Click to See Complete Forum and Search --> : Recurring Popup Help


monotoba
12-12-2003, 03:12 PM
Hello all, I am new to JavaScript programming and I am looking for a way to provide a popup window containing an html file to be displayed for site subscribers. My JavaScript is being included in a php file.

At the moment I have three files:
1. nmemeber.php -- Checks to see if the user is registered and includes nmember.js if they are not.

2. nmember.html -- my html message to non subscribers.

3. nmember.js -- This is where I'm having trouble... This file opens a window, sets the timeout period and call function.

The object is to open a new popup window every 'x' seconds if one is not already open. If a window is open, then bring the window to the foreground. If the user has closed the popup window, then re-open it.

My code looks like this:
**Note: the line "pwindow.closed() causes an error stating that this method is not supported... and does not function!

--------------------------------------------------------------------
var pwindow;
var tim;

function nmember_timeout()
{
// display the popup
//popupwindow=window.setTimeout("nmember_timeout()", 60000);

if((!pwindow) || (pwindow.closed()))
{
pwindow=window.open("templates/popup_member.html","", "top = 40, left= 40, width=500, height=450, scrollbars");
}
else
{
pwindow.focus();
}
// set the interval
window.setTimeout("nmember_timeout()", 30000);
}

nmember_timeout();

----------------------------------------------------------------------

Thanks for your help with this...

dadinos
12-12-2003, 04:20 PM
Hi,

Try something like this!

Regards

file:startpopup.html
<html>
<head>
<script langiage='javascript'>
var pwindow;
var tim;

function nmember_timeout()
{
if(!pwindow)
{
window.open("content.html","pwindow", "top = 40, left= 40, width=500, height=450, scrollbars,alwaysRaised");
}
// set the interval
window.setTimeout("nmember_timeout()", 3000);
}

nmember_timeout();

</script>
</head>
</html>

file:content.html
<html>
<body onblur="self.focus()">
<p> What you want to display stays on top!</p>
</body>
</html>

monotoba
12-13-2003, 03:23 AM
Thanks but the above code didn't provide the needed functionality. However, I found a work around that allowed the functionality I needed. I also need to seperate the html content entirely from the java script and the suggested code does not provide for this.

The problem was caused by the fact that my browser (EI 6.0.28) does not support the 'window.closed()' method. I could not find a way to test for a window existing without causing an error if the window had been closed. The solution was to place the 'window.focus()' method in a 'try/catch' statement. This allowed me to catch the error and act accordingly.

Here is the code:

var pwindow;
var tim;

function nmember_timeout()
{

// display the popup
if((!pwindow))
{
pwindow = window.open("templates/popup_member.html","", "top = 40, left= 40, width=500, height=450, scrollbars");
}
else
{
try
{
pwindow.focus();
}
catch (err)
{
pwindow = null ;
}
}

// set the interval
window.setTimeout("nmember_timeout()", 60000);

}


nmember_timeout();


I hope this helps anyone wanting to accomplish the same type of task.


;)