Solved

AJAX PHP Chat load Iframe and scroll to the bottom

Posted on 2008-10-31
1
864 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

773 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