www.webdeveloper.com
Results 1 to 9 of 9

Thread: Check if popup window is open ?

  1. #1
    Join Date
    May 2008
    Posts
    9

    Check if popup window is open ?

    Hi,
    I am trying to make a chat application. So within that when a user1 sends a private chat to user2 ,a popup should show at user2's screen. I did now i need to code to check whether the poped up window is open or close that ,if it is closed i need to popup it again ?


    Does anyone know this? If yes , please advice.

  2. #2
    Join Date
    Apr 2008
    Posts
    102
    Well it sounds like for what your trying to do, you'd need to use ajax and PHP. The ajax part can be used to check a PHP page that would every 5 seconds or so send private messages added to a database and at the same time it also checks to see if the last ones were recieved and if they weren't, then re-send the alert. Most chat scripts have features similar to that so you can always find a script like that here.

    Hope this helps.
    - Josh
    Website Coder and Pixel Artist

  3. #3
    Join Date
    May 2008
    Posts
    9

    Thank you.

    Yes. I am using ajax and php everything as u said. But the problem is to check whether the prev popup is open or not.
    Otherwise it opens new popup each time when a private msg is send.
    Thanks 4 the refernces.
    Do you knw any specific code for my issue?

  4. #4
    Join Date
    Apr 2008
    Posts
    102
    Well after the part of the script that alerts the user, place this ...

    PHP Code:
    <?

    echo '<script language='javascript'>window.open("delete.php","","width=50,height=50,status=no,toolbar=no,menubar=no")</script>';

    ?>
    ... and on delete.php put your code that removes the alert from a database and put this at the end of the page ...

    PHP Code:

    echo '<script language='javascript'>window.opener='x'; window.close();</script>'
    All of this basically just opens a popup window that has a page that will delete the alert from the database and it then closes the same popup so no one knows. (It all happens in less than a second)

    I haven't tested the idea but it should work.

    Hopefully this helps.
    - Josh
    Website Coder and Pixel Artist

  5. #5
    Join Date
    May 2008
    Posts
    9
    thanks!
    May i know what is that window.opener coder for?


    Is there directly a code to check whether the window is open or not?
    like if (my_window.closed() ) {
    }


    ??

  6. #6
    Join Date
    Apr 2008
    Posts
    102
    The reason I included the window.opener part is because if you don't, then the popup will tell the user that its trying to close the window and it'll ask if they want to proceed. The window.opener should fix that and make it close anyway.

    I don't think you can close it the way you mentioned but I'm not sure. You could probably use a div maybe?
    - Josh
    Website Coder and Pixel Artist

  7. #7
    Join Date
    May 2008
    Posts
    9
    Well, i had used window.open. It opens a small popup window, but when i close it it doesnt ask anything.
    The exact problem i am facing is like this:
    user1 sends a private chat and using window.open user 2 gets popup opened. That works perfect. The thing what happens is, if user1 or user2 closes that popup it wont open again.

    Can you advice me on that?

  8. #8
    Join Date
    Apr 2008
    Posts
    102
    You can include the alert.php page like ...

    PHP Code:
    <?

    include "../alert.php";

    ?>
    ... and on the alert.php page put a meta refresh like this ...

    HTML Code:
    <meta http-equiv="refresh" content="5">
    Is that what your trying to do?
    - Josh
    Website Coder and Pixel Artist

  9. #9
    Join Date
    May 2008
    Posts
    9
    Thanks! .. I fixed it.


    Thank you very uch. Your help is really appreciated.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles