www.webdeveloper.com
Results 1 to 7 of 7

Thread: reload page on server from popup

  1. #1
    Join Date
    May 2007
    Posts
    52

    Question reload page on server from popup

    I made the following post in the javascript section but i am thinking it might also work server-side so thought it best to post it in here

    ----------------------
    I have a small problem and i was wondering if some could please help?

    i have a chat room page and i have added a popup so you can edit your posts for x amount of time,

    The problem is:
    when you submit the form in the popup i need the chat room page to refresh for everyone,

    This is what i have:
    at the moment i have the following simple code that is exacuted at the end but it only refreshes the page for the 1 user (client-side)


    Code:
    <script type="text/javascript"> 
    function refreshOpener(){ 
        if(opener && !opener.closed){
            opener.location.reload();
        }
    } 
    </script>
    is there a way i can make the chat room page refresh for everyone from within the popup?


    In Short:
    the popup on the chat room page needs to refresh the chat room page for everyone


    any help would be much appreciated

  2. #2
    Join Date
    Apr 2007
    Posts
    1,664
    Short answer, no, once the page has loaded there is no comunication with the server until it has loaded again. You have to set a way to refresh the page for each user. Ajax can handle this nicely by calling a 'heartbeat' function (setInterval) that polls for new posts in chat every few seconds with minimal bandwidth requirements. That way the whole page doesn't have to reload. If you don't want to use ajax then you'll need to refresh the page. You can use a meta refresh on an iframe to poll the database and when it finds a new message send a reload message to the parent frame.
    Last edited by SyCo; 04-20-2009 at 05:17 PM.

  3. #3
    Join Date
    May 2007
    Posts
    52
    Thank you for your input,

    however,

    my chat already works fine as it just retrives the last post after the message button is submitted,

    But i have now added a "edit post" witch is within a popup on the page,


    all i need to do is a meta refresh on the chat room page if the "edit post" form from popup window is submitted, if you get what i mean,

  4. #4
    Join Date
    Apr 2007
    Posts
    1,664
    The problem is:
    when you submit the form in the popup i need the chat room page to refresh for everyone,
    You can't refresh the chat room for other users. You can have every user send a message from the browser to the server at intervals. The server cannot initiate a conversation with a browser.

    If I edit my post you can't see it unless the browser gets more info, be it from a page refresh, a meta refresh or an ajax call.

    The browser holds the most recent record when it first loads. All user's browsers in the chat room can poll the database. That means the browser sends a message to select the latest record. When the original one it is holding is not as new as the one in the database it sends a reload signal. But all the user's browsers must constantly (every few seconds) poll the database to compare their original record with the latest.

    is there a way i can make the chat room page refresh for everyone from within the popup?
    No, unless you have all users refresh their browser (or div with ajax)
    Last edited by SyCo; 04-20-2009 at 06:26 PM.

  5. #5
    Join Date
    May 2007
    Posts
    52
    how would i go about refreshing a div on the chat room page from within the popup using ajax, or is that still not possible?

  6. #6
    Join Date
    May 2007
    Posts
    52
    i was thinking along the lines of passing a variable to the chat room page from the popup and having a conditional statment that will do a meta refresh only if a user submits an "edit post"

    i can do this if i add the "edit post" on the same page as the chat room but it looks better being in its own popup

  7. #7
    Join Date
    Apr 2007
    Posts
    1,664
    Use the javascript setInterval() to call an ajax function. The ajax function polls the database for new or edited posts.

    If you're new to ajax then you'll need to run through a tutorial or two to understand it. I like xajax from http://xajaxproject.org as it's easy for PHP developers with minimal javascript skills to develop feature rich ajax apps. Check out their tutorials and wiki.

Thread Information

Users Browsing this Thread

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

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