Solved

AJAX PHP Chat load Iframe and scroll to the bottom

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

758 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

20 Experts available now in Live!

Get 1:1 Help Now