Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

AJAX PHP Chat load Iframe and scroll to the bottom

Posted on 2008-10-31
1
Medium Priority
?
902 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 500 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

971 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