473,795 Members | 3,002 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.g etElementById(' 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 9137

writeOnceDebugE verywhere() 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.g etElementById(' 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
writeOnceDebugE verywhere() 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.g etElementById(' 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.getEle mentById(id);
var newP = document.create Element('p');
newP.appendChil d(document.crea teTextNode(aCou nter++ + ' ' +txt));
mDiv.appendChil d(newP);

if (newP.scrollInt oView) {
newP.scrollInto View(true);
} else if ('number' == typeof mDiv.scrollTop) {
mDiv.scrollTop = 10000;
}

}

</script>
</head>
<body>
<input type="button" value="Add text"
onclick="addPar a('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
6576
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
1613
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" style="height:185px;width:390px;overflow:scroll;z-index: 91; position: absolute; visibility:visible;left:15px;top:67px;"></div> And I have a function that adds text to this div: function addText(t)
3
1137
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 2005<BR>');"> <b>HELLO</b> </a> <div id=MyDiv style=height:200;overflow:auto class=normal style="border:1px
1
5711
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 of selected items has a column header and differentiation between odd and even rows. This part is trivial. Clients have the ability to re-order the list of selected items. This is also trivial: I trap the onClick event for a row to select it. ...
5
4269
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 text.. ' function scrollMsg(){
3
11759
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 any idea or trick of how to achieve this? Appreciate your ideas..... Thanks Chamnap
2
2043
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 http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>WELCOME TO HEMA CREATIVE HOUSE</title> <style type="text/css"> <!-- @import url("css/IDESIGN 1.css"); @import url("css/IDESIGN.2.css"); body {
22
4753
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 WBS TaskID No. of Resource St.Date End.Date Duration 1 asdkfa 2 asdfasd asdfdas asdf 1.1 asdkfa 2 asdfasd asdfdas asdf 2 asdkfa ...
8
3370
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 through with the down arrow or page down, it seems that items get caught in the buffer making scrolling through large amounts of objects cumbersome. After taking my finger off the key, the cursor continues to move. If I push down and let go quickly,...
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10439
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9043
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.