Solved

AJAX PHP Chat load Iframe and scroll to the bottom

Posted on 2008-10-31
1
859 Views
Last Modified: 2008-11-01
Hello,

I have a fairly simple question, but I cannot seem to get it to work. I am creating a simple online chat application, and the html page for the chat contains a textbox to submit new messages. The html page also contains an iframe to another html page that dynamically loads the messages. The problem I am having is that I want the iframe to scroll to the bottom when the page is first loaded and when the user posts a new message. I also want to be able to detect when the scrollbar is at the bottom and when another user posts the scroll bar scrolls to the bottom displaying the new message. If you could help me out with this I'd really appreciate it. If you could show me how I might go about doing this and provide some code examples, I'd really appreciate it.

Here is a snippet of the html page that contains the iFrame:
<!-- Here is where the AJAX Javacript code is -->
 
 

<table width="100%"  border="0" cellpadding="3" cellspacing="4" bgcolor="#000000">

<tr>

  <td bgcolor="#006699">Chat App</td>

</tr>

<tr cellpadding="0" cellspacing="0">

<td bgcolor="#ffffff" cellpadding="0" cellspacing="0">
 

<div bgcolor="#ffffff">

<iframe frameBorder="0"

src ="get_messages.html"

width="100%">

</iframe></div>

</td>

</tr>

<tr>

<td>
 

  <form onsubmit="postMessage(textvalue.value)">

  <input type="text" id="textvalue"  />

  <input type="submit" value="snd"  />

  </form>
 

</td>

</tr>

</table>

Open in new window

0
Comment
Question by:tfilms
1 Comment
 
LVL 13

Accepted Solution

by:
Xyptilon2 earned 125 total points
ID: 22856905
Fastest non-javascript way is to place an HTML anchor at the bottom of the page like <a name='anchor'></a> And post to whatever.php#anchor

You won't need javascript for that. Or if you want to use javascript:

if (document.body.scrollHeight) {
  window.scrollTo(0. document.body.scrollHeight);
}
else if (screen.height) { // IE5
  window.scrollTo(0. screen.height);
}

something like this should work
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now