powerpro
10-13-2003, 04:27 PM
These are posts from my codingforums.com thread, please help, the answer they gave me won't work.
Hello,
I posted this message on a PHP forum on phpbuilder.com, I figured since this is entirely a JavaScript problem, and everything with the PHP is working fine, I should post here.
Here is what I said:
Hello,
I am having some difficulties when using PHP to output some JavaScript code. Actually, this is more of a JavaScript problem, but I figured since PHP was outputting it, this would be a good place to ask.
Anyway, here is what I have:
I have 2 PHP scripts, both are in iframes from a main HTML page, one page (call it A) refreshes whenever it detects a new entry to the database (uses remote PHP and JavaScripts to accomplish this and works fine), and the other page (call it B) refreshes every 7 seconds.
From B, a user clicks a link to open a new window, in the new window, they are able to add a new entry to the database.
From A, once this new entry is detected, it outputs a JavaScript.
Now, here is my problem:
This JavaScript is SUPPOSED to check to see if the user all ready has a window open, if so, focus on it, if not, open a new window.
The thing is, I can't figure out how to detect if the window is all ready open, I know how to do the focusing and the opening of a new window. But without being able to detect if the window is all ready open, it's useless.
I came to the conclusion that if I simply opened a new window, it would just reload the window if it's all ready open (because they all have the same name) and open it if it's not open. But I can't have that happen because if someone is typing a message in that new window, and it reloads, they lose the message.
Please help, any help provided is appreciated.
Thanks.
code:--------------------------------------------------------------------------------
var popup;
function openPopup(){
if (popup && !popup.closed) {
popup.focus();
return;
}
popup = window.open(...);
popup.focus();
}
--------------------------------------------------------------------------------
__________________
Glenn
I'm still having no luck.
Please help any way you can.
Here's the JavaScript code to call the code you gave me (I think something's wrong with this, I put test alerts in the code you gave me and none of them showed up, but this JavaScript was still in the source):
<script language="JavaScript" src="javascripts.php?chatwin&user=user">
pmGet();
</script>
Here's the modified code you gave me (external JS file):
<!-- Begin
var myChilduser;
function pmGet () {
if (myChilduser && !myChilduser.closed) {
myChilduser.focus();
return;
}
myChilduser = window.open(url,"Childuser"," toolbar=0,scrollbars=0,location=0,statusbar=0,menu
bar=0,resizable=0,width=540,height=200");
myChilduser.focus();
}
// End -->
Here's the code to open the original window (external JS file):
<!-- Begin
function pmSend () {
url="private.php?user";
myChilduser = window.open(url,"Childuser"," toolbar=0,scrollbars=0,location=0,statusbar=0,menu
bar=0,resizable=0,width=540,height=200");
}
// End -->
Thanks in advance for any help provided.
- PowerPro
Hello,
I posted this message on a PHP forum on phpbuilder.com, I figured since this is entirely a JavaScript problem, and everything with the PHP is working fine, I should post here.
Here is what I said:
Hello,
I am having some difficulties when using PHP to output some JavaScript code. Actually, this is more of a JavaScript problem, but I figured since PHP was outputting it, this would be a good place to ask.
Anyway, here is what I have:
I have 2 PHP scripts, both are in iframes from a main HTML page, one page (call it A) refreshes whenever it detects a new entry to the database (uses remote PHP and JavaScripts to accomplish this and works fine), and the other page (call it B) refreshes every 7 seconds.
From B, a user clicks a link to open a new window, in the new window, they are able to add a new entry to the database.
From A, once this new entry is detected, it outputs a JavaScript.
Now, here is my problem:
This JavaScript is SUPPOSED to check to see if the user all ready has a window open, if so, focus on it, if not, open a new window.
The thing is, I can't figure out how to detect if the window is all ready open, I know how to do the focusing and the opening of a new window. But without being able to detect if the window is all ready open, it's useless.
I came to the conclusion that if I simply opened a new window, it would just reload the window if it's all ready open (because they all have the same name) and open it if it's not open. But I can't have that happen because if someone is typing a message in that new window, and it reloads, they lose the message.
Please help, any help provided is appreciated.
Thanks.
code:--------------------------------------------------------------------------------
var popup;
function openPopup(){
if (popup && !popup.closed) {
popup.focus();
return;
}
popup = window.open(...);
popup.focus();
}
--------------------------------------------------------------------------------
__________________
Glenn
I'm still having no luck.
Please help any way you can.
Here's the JavaScript code to call the code you gave me (I think something's wrong with this, I put test alerts in the code you gave me and none of them showed up, but this JavaScript was still in the source):
<script language="JavaScript" src="javascripts.php?chatwin&user=user">
pmGet();
</script>
Here's the modified code you gave me (external JS file):
<!-- Begin
var myChilduser;
function pmGet () {
if (myChilduser && !myChilduser.closed) {
myChilduser.focus();
return;
}
myChilduser = window.open(url,"Childuser"," toolbar=0,scrollbars=0,location=0,statusbar=0,menu
bar=0,resizable=0,width=540,height=200");
myChilduser.focus();
}
// End -->
Here's the code to open the original window (external JS file):
<!-- Begin
function pmSend () {
url="private.php?user";
myChilduser = window.open(url,"Childuser"," toolbar=0,scrollbars=0,location=0,statusbar=0,menu
bar=0,resizable=0,width=540,height=200");
}
// End -->
Thanks in advance for any help provided.
- PowerPro