Click to See Complete Forum and Search --> : Remote Windows, Please Help


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

Dimitri
10-13-2003, 05:09 PM
Can you simplify what exactly it is you want help on?

Are you asking us for help on detecting whethere a window exists?

Or asking if you want to also check whether a particular form field in a window (which may or may not be open) contains text that a user has type in? If so, what are you asking for help on in this situation?

I'll be happy to help, but I need you to clarify your problem more clearly.

Dimitri

powerpro
10-13-2003, 05:57 PM
Oh, sorry for not clarifying, I would like to detect if the window exists, you can view my code to see what I am currently doing, which isn't working.

I want to detect if the window exists, so if it does, I focus on it, and if it doesn't, I open a new window.

Right now it doesn't work at all from what I can tell.

There may also be a problem when I call the script using my JavaScript tags which I also provided.

Thanks.


- PowerPro

powerpro
10-13-2003, 06:02 PM
I should also note that the first window(A) that initially opens a new window(C), is separate from the other window(B) which detects to see if the new window(C) is open.

The 2 windows(A&B) are in iframes from a main HTML page. This is all part of a live chat script I'm making.

Thanks for your help.


- PowerPro

Dimitri
10-13-2003, 06:46 PM
I don't want to look through your code. Instead, I'll give you code that solves the problem you stated (I'll leave it up to you to incorporate it into your pages). There are simpler ways to do tis, but for now... I just want to show you ONE way.

Put this function into two test pages that will be loaded inside the frames (name the pages whatever you want):

&nbsp;&nbsp;&nbsp;&nbsp;<script>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function foo(page) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var test = window.open(page, "test_window");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (test.document.title) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;test.location.href = page;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert("window already exixted. used existing window to load in the URL");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;test.location.href = page;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert("previous window didn't already exsit. open a new window.");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;</script>

Next, in these two test pages (one test page per frame) add one of the following links to each of these test pages (or create your own links if you prefer):

<a href="javascript:foo('http://www.YOURDOMAIN.html')">Open a test window</a>
<a href="javascript:foo('http://www.YOURDOMAIN.com')">Open another test window</a>

Make SURE that all these pages belong in the SAME DOMAIN. In other words, make sure that they all originate from YOUR domain, AND make sure these test pages contain titles between their <title></title> tags (otherwise this script won't work).

Got it?
* One html page that has two frame windows
* two test pages that are loaded into each of the frame windows
* the script above should be in BOTH test pages
* each page should contain at least one of the above links

Cheers.
Dimitri

powerpro
10-13-2003, 07:18 PM
Sorry, you very much misunderstood me. :(

I will try some other methods on my own.

Thanks anyway.


- PowerPro

Dimitri
10-13-2003, 08:09 PM
You don't want to say what part I misunderstood?

Ok..... well then... good luck.
Dimitri