SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript Chat scrolldown Problem

    Hi, I just wrote a little PHP/MySQL/JavaScript Chat which works fine. I found this Java-Script to add the new lines to the existing one :

    [VBS]
    if (document.all) {
    top.wOut.document.body.innerHTML+= toOut;
    } else {
    top.wOut.document.write("<html><style>BODY {font-family: Verdana, sans-serif; color: #000055; font-size: 12px;} </style><body bgcolor='#FFFFFF'>");
    top.wOut.document.write(toOut);
    [/VBS]

    it works fine, the only problem ist that the window does not scroll down automatically, so the user always has to scroll down on his own.
    Any ideas here ?

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Probably

    You could use the following:

    (if you're using a div [id=hold] with overflow:scroll)

    var dH=document.getElmentById('hold');

    dH.scrollTop=dH.scrollHeight-dH.style.pixelHeight;

    Hope this gives you an idea.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, I'm not so familiar with JavaScript, where do I have to place this code ?
    I just placed it below mine, but id didn't have any afffect.
    Thanks, Alex

  4. #4
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well you really do need to know Javascript to do this, i'm afraid, and without actually SEEING the page (url if you have it) i can't really say

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  5. #5
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would really be appreciate if you could help me with this. I also have another problem with this script.
    Sometimes it workes, sometimes just not. I have no idea why ?
    Here is the script :

    PHP Code:
    <?
    include("../login.php");
    ?>
    <html>
    <body bgcolor="#FFFFFF">
    <script>
    function refresh() {
        time = new Date()
        window.location='receive.php?tstamp='+escape(time);
    }
    <?
        dbConnect
    ('');
        
    $get mysql_query("SELECT send_id AS name, message, rcpt_id, send_id FROM message LEFT JOIN online ON message.time>online.lastclick WHERE online.id='$myid'");
        while(
    $getarray mysql_fetch_array($get)){
        
    extract($getarray);
        
            
    $toOut '<font color="#336666"><b>'.$name.'&gt;</b></font> '.$message.'<br>';

          
    ?>
          toOut = '<? echo $toOut ?>';
          if (document.all) {
            top.wOut.document.body.innerHTML+= toOut;
          } else {
            top.wOut.document.write("<html><style>BODY {font-family: Verdana, sans-serif; color: #000055; font-size: 12px;} </style><body bgcolor='#FFFFFF'>");
        top.wOut.document.write(toOut);

          }
          <?
        
    }
     
        
    $update mysql_query("UPDATE online SET lastclick = now(), expiry=expiry");
    ?>
    setTimeout('refresh()',15000);
    </script>
    </html>
    ________________
    ... I hate JavaScript

  6. #6
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I'm a pgsql and Mason man

    but still i'd want to throw the php equiv of:

    if ($conn->errorMessage){
    handle($conn->errorMessage);
    }

    to handle the event of a db error.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  7. #7
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You mean the JavaScript is fine ?

  8. #8
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    nope :p !

    No, the JS is dependant on a timeout, this WILL fall over occasionally!

    The better way of doing it would be to test the location for complete:

    while (!document.whatever.complete){
    loop_control++;
    }
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  9. #9
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, but this is just like spanish for me.
    Could you please show me how to reload the page every x seconds and add the new text to the existing one.
    I think this is really advanced staff, I just searched a bit for any tutorials but couldn't find any.

    thanx, alex

  10. #10
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sorry !

    I could help you out LOADS, so i guess me telling you i don't have time is kind of teasing.

    The way I would do it is this:

    NO NO NO! lol

    You should NOT be using reload to achieve this.

    You could easily do it with "remote scripting" as I define it (not in it's real definition)... in otherwords:

    You maintain a database with all the currently attached users, and their last connection time.
    Every 5 seconds you send a remote script request to the server for new posts.
    The server parses the database for newer messages than your last connect, and puts them in the return external js file. The js file then appends the new text to the bottom of your divider, and scrolls the divider down.

    End of story, what do you think?

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  11. #11
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Sorry !

    Originally posted by Flawless_koder
    The js file then appends the new text to the bottom of your divider, and scrolls the divider down.
    Yes, this is exactly what I'm just trying to do, but without success.

  12. #12
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .oO( lost concept )

    I just outlined an entirely different approach to the entire concept, but if you're gonna stick to your guns:

    You need to show me what you have

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  13. #13
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?
    include("../login.php");
    ?>
    <html>
    <body bgcolor="#FFFFFF">
    <script>
    function refresh() {
        time = new Date()
        window.location='receive.php?tstamp='+escape(time);
    }
    <?
        dbConnect
    ('');
        
    $get mysql_query("SELECT send_id AS name, message, rcpt_id, send_id FROM message LEFT JOIN online ON message.time>online.lastclick WHERE online.id='$myid'");
        while(
    $getarray mysql_fetch_array($get)){
        
    extract($getarray);
        
            
    $toOut '<font color="#336666"><b>'.$name.'&gt;</b></font> '.$message.'<br>';

          
    ?>
          toOut = '<? echo $toOut ?>';
          if (document.all) {
            top.wOut.document.body.innerHTML+= toOut;
          } else {
            top.wOut.document.write("<html><style>BODY {font-family: Verdana, sans-serif; color: #000055; font-size: 12px;} </style><body bgcolor='#FFFFFF'>");
        top.wOut.document.write(toOut);

          }
          <?
        
    }
     
        
    $update mysql_query("UPDATE online SET lastclick = now(), expiry=expiry");
    ?>
    setTimeout('refresh()',15000);
    </script>
    </html>

  14. #14
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Use something

    You have no content management.

    Put the posts into a divider, and set the scrollTop of the divider to be the scrollHeight of the divider - the pixelHeight of the divider.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  15. #15
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    great thanks

  16. #16
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Strange feeling

    I've got a strange feeling you're not quite with me on this one.
    If you have any problems implementing, just let me know and i'll take a look at what you've got or guide you through it better.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---


Bookmarks

Posting Permissions

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