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 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Oct 2003
    Location
    Rylstone, Australia
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    can I rewrite the contents of a frame without reloading the frame

    Yo!

    I am working on a web-based IM app. Currently It is running in a pop-up window which is divided into three horizontal frames (header, main message display area, and message input area).

    It is all working OK, but I am currently refreshing the display frame every 2 seconds so that it will display any new messages that have been sent (using PHP and MySQL for backend stuff). The problem is that with IE it makes a horrible clicking sound on each refresh and the hourglass icon briefly flashes on the screen.

    These are not affecting the app as such but it would be nice if I could do it another way so that this did not occur...is it possible? I have been told that with javascript I may be able to get the new page contents without actually doing a refresh/reload of the frame.

    Any suggestions welcome.

    TIA

    chameleon

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're asking about an elemental Javascript capability:

    Code:
    document.frames["name of the frame"].document.open();
    document.frames["name of the frame"].document.write("content here, multiple write statements are ok");
    document.frames["name of the frame"].document.close(); // This line is where the new contents should be complete and ready for the user
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    New to the CF scene
    Join Date
    Oct 2003
    Location
    Rylstone, Australia
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmm... not really what I want I think.

    I might be wrong but it seems that this sort of thing can only update frames that are within the the same users client. I need the browser to fetch new data from a database every 2 secs or so and display it in the frame for every user that is logged on. So if user 'a' types in 'hello' it will apear in all other user's display frames (within 2 secs or whatever refresh rate is).

    The best I could get it to do with a variation* on your js code was to update the messages in the users browser only when they sent a message (ie their own message would appear in the display along with any other messages that were sent by others users since this users last post, BUT other users displays are not updated until they send a message, obviously)

    The reason for this is that on sending their message a php script is run that reloads the necessary frames with the new data. But I cannot get new external data into the document.write() call without reloading the page through the php script.

    Is there some way I can load a (php generated) page into the frame with the document.open() call (as for window.open()) or otherwise?

    Thanks for your suggestion anyhow.

    chameleon

    * I had to use the following code to get any kind of functionality:

    Code:
    parent.window.frames[2].document.open();
    parent.window.frames[2].document.write("<linkrel='stylesheet'
       type='text/css' href='css/helpLine.css'><div class=\"chat-box\">
       <?echo $messages; ?></div>");
    parent.window.frames[2].document.close();

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    try
    Code:
    function getMessages(){
      var xmlhttp;
      var responseText = '';
      if (ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
        xmlhttp.Open("GET", "http://mydomain.com/messages.php", false); 
        xmlhttp.send();
        if (xmlhttp.status==200){
          parent.window.frames[2].document.getElementById('chat-box').innerHTML = xmlhttp.responseText;
        }
      }
    }
    call that function every 2 secs. I recommend using a longer delay coz as the messages get longer, the response of the server would be slower.
    It can also be made to work with Mozilla and NS7. Just google it.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    try using


    document.getElementById(id).innerHTML = "new content text here...";

    instead of document.write

    and see that there must be an ActiveX method of refreshing a server-side application
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    oops :-) I see that glenngv already gave you the same but a more compresesive advice.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    New to the CF scene
    Join Date
    Oct 2003
    Location
    Rylstone, Australia
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks glenngv, I'll give it a go tomorrow (gettin' late here in Aus). The php script only ever sends the last 20 messages to be displayed so the reload time is usually ok. I don't really know much about ActiveX stuff(not being much of a MS man), looks like I need to do some nore reading ;-).

    And yeah even though IE has the major market share I still want it to work properly on Mozilla, cause its what I use and I hate it when I get IE only coded pages ;-)

    cheers, chameleon

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    As I said in my previous post, you can use XMLHTTP in Mozilla. I googled it for you.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #9
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #10
    New to the CF scene
    Join Date
    Oct 2003
    Location
    Rylstone, Australia
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks all,

    I'll post back once I've had a chance to rewrite the necessary parts and get it all working.

    cheers,

    chameleon

  • #11
    New to the CF scene
    Join Date
    Oct 2003
    Location
    Rylstone, Australia
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    great, I've got it working nicely on Mozilla and IE, thanx everyone for your help.

    cheers,

    chameleon


  •  

    Posting Permissions

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