Solved

AJAX PHP Chat load Iframe and scroll to the bottom

Posted on 2008-10-31
1
869 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

740 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