Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question JavaScript Remote Windows

    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.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,047
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    var popup;
    function openPopup(){
      if (popup && !popup.closed) {
         popup.focus();
         return;
      }
      popup = window.open(...);
      popup.focus();
    }

  • #3
    New Coder
    Join Date
    Oct 2003
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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,menubar=0,resizable=0,wid th=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,menubar=0,resizable=0,wid th=540,height=200");
    }

    // End -->


    Thanks in advance for any help provided.


    - PowerPro

  • #4
    New Coder
    Join Date
    May 2003
    Location
    UK
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    no comments

    I have had many problems with javascript where it didn't work on particular browsers...


    The first thing to do is remove the comments <!-- and //--> from your external .js files.

    Maybe it won't fix your problem but it will fix problems with getting your final version to work cross browser.
    They only tell you its a stupid question when they don't know the answer!

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,047
    Thanks
    0
    Thanked 251 Times in 247 Posts
    michael is correct. you should remove the <!-- //--> comments in the external js. You only put them when scripts are embedded in the html.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •