473,396 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Scrolling down after modifying div.innerHTML ?

- I believe it is a simple question:
my onclick event for the button looks as follows:

......
// reference to the <div id="messages" :
var mDiv=document.getElementById('messages');
mDiv.innerHTML += 'bla.. bla.. bla';
mDiv.innerHTML += '<br/>';

- at the some point, when <div> area becomes full, I want somehow to
scroll down, because of I cannot see last added message without manualy
scrolling down.
My question is, wheter is possible, and how ?

Jan 4 '06 #1
2 9083

writeOnceDebugEverywhere() napisal(a):
- I believe it is a simple question:
my onclick event for the button looks as follows:

......
// reference to the <div id="messages" :
var mDiv=document.getElementById('messages');
mDiv.innerHTML += 'bla.. bla.. bla';
mDiv.innerHTML += '<br/>';

- at the some point, when <div> area becomes full, I want somehow to
scroll down, because of I cannot see last added message without manualy
scrolling down.
My question is, wheter is possible, and how ?


Keywords: scrollTop, scrollHeight.
Caveat: Non-standard, buggy.

Jan 4 '06 #2
writeOnceDebugEverywhere() wrote:
- I believe it is a simple question:
my onclick event for the button looks as follows:

......
// reference to the <div id="messages" :
var mDiv=document.getElementById('messages');
mDiv.innerHTML += 'bla.. bla.. bla';
mDiv.innerHTML += '<br/>';
Rather than just plonking text and <br> elements into the div,
consider using DOM and appending P elements with text content.


- at the some point, when <div> area becomes full, I want somehow to
scroll down, because of I cannot see last added message without manualy
scrolling down.
My question is, wheter is possible, and how ?


Yes, but it requires non-standard (and therefore unreliable)
scripting. Try the following, which should cover most browsers and
fail gracefully (i.e. do nothing) where not supported.

It attempts to use scrollIntoView. If that's not supported, it tries
scrollTop. If neither work, nothing happens.

It works in Safari 1.0.3 and Firefox 1.5. As far as I can tell it
/should/ work in IE 5.2 (Mac) but it doesn't. It should work in IE 6
on Windows and maybe IE 5 too.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><title>...</title>

<style type="text/css">
#xx { height: 5em; width: 15em; border: 1px solid red;
overflow: scroll; }
</style>
<script type="text/javascript">

// Just to make new lines obvious
var aCounter = 0;

function addPara(id, txt)
{
var mDiv = document.getElementById(id);
var newP = document.createElement('p');
newP.appendChild(document.createTextNode(aCounter+ + + ' ' +txt));
mDiv.appendChild(newP);

if (newP.scrollIntoView) {
newP.scrollIntoView(true);
} else if ('number' == typeof mDiv.scrollTop){
mDiv.scrollTop = 10000;
}

}

</script>
</head>
<body>
<input type="button" value="Add text"
onclick="addPara('xx', 'Blah blah blah');">
<div id="xx"></div>
</body>
</html>

Feature testing ignored for brevity.
--
Rob
Jan 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alain | last post by:
Hello, I would like this script to work from up to down (reverse direction) : http://www.sites-web.com/temp/vscroll_down_up.html Many thanks :) Alan <html>
2
by: chris | last post by:
Hello all - I'm trying to get a div element to scroll down when a new line of html is added to it. Here's my div element: <div id="initialtext"...
3
by: Mel | last post by:
i have the following code and need to scroll the div to the bottom on each of the inserts. please help *&^%$#@ <a href=# onclick="addtext('Wed Mar 23 11:23:58 AM Eastern Standard Time...
1
by: dschectman | last post by:
I have an interesting issue. I need to implement a dynamic table to mimic a select list. Each time you double click from the master list, a row is added to the list of selected items. The list...
5
by: PythonistL | last post by:
I am a newbie with Javascript. I have this simple script for scrolling text <HTML> <HEAD> <TITLE>Scrolling Message Script</TITLE> <SCRIPT language="JavaScript"><!-- var msg = 'My scrolling...
3
by: Chamnap | last post by:
Hello everybody, I have one problem. I want to do something after the user finished scrolling. The scroll event fires whenever the user is scrolling. I don't want this actually. Does anyone has...
2
by: gunnuk | last post by:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta...
22
RamananKalirajan
by: RamananKalirajan | last post by:
Hello I am working on WorkBreak Down structures, but i was unable to finish it perfectly. I am posting my code with this. I have to finish this task. please help me out. It must form like this ...
8
by: rmurgia | last post by:
Has anyone noticed that scrolling through objects i.e. forms, reports, tables, etc with Access 2007 is not as easy as Access 2003? I have a database with a large number of objects. When scrolling...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.