I want to display HTML text inside a div and have the page open scrolled to
the bottom. (My div has overflow:auto so that it appears with scroll bars)
I have found this that works on a textarea:
document.all.MyDivId.scrollTop = document.all.MyDivId].scrollHeight;
But this doesn't work on a div. I am using a div because the text I am
displaying contains HTML. Surely it is possible to simply set a scroll bar
to the bottom in a div??? Thanks! 14 12421
Simon Wigzell wrote: I want to display HTML text inside a div and have the page open scrolled to the bottom. (My div has overflow:auto so that it appears with scroll bars)
I have found this that works on a textarea:
document.all.MyDivId.scrollTop = document.all.MyDivId].scrollHeight;
No it doesn't, you just think it does.
But this doesn't work on a div. I am using a div because the text I am displaying contains HTML. Surely it is possible to simply set a scroll bar to the bottom in a div??? Thanks!
Yep, its possible.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Simon Wigzell wrote: I want to display HTML text inside a div and have the page open scrolled to the bottom. (My div has overflow:auto so that it appears with scroll bars)
I have found this that works on a textarea:
document.all.MyDivId.scrollTop = document.all.MyDivId].scrollHeight;
But this doesn't work on a div. I am using a div because the text I am displaying contains HTML. Surely it is possible to simply set a scroll bar to the bottom in a div??? Thanks!
Nor will it work in any browser that doesn't support Microsoft's
proprietary document.all.
Why wont an anchor work?
--
Rob
Simon Wigzell wrote: I want to display HTML text inside a div and have the page open
scrolled to the bottom. (My div has overflow:auto so that it appears with scroll
bars) I have found this that works on a textarea:
document.all.MyDivId.scrollTop = document.all.MyDivId].scrollHeight;
But this doesn't work on a div. I am using a div because the text I
am displaying contains HTML. Surely it is possible to simply set a
scroll bar to the bottom in a div??? Thanks!
Try this...
<script type="text/javascript">
function scrollDiv()
{
var el;
if ((el = document.getElementById('MyDivId'))
&& ('undefined' != typeof el.scrollTop))
{
el.scrollTop = 0;
el.scrollTop = 5000;
}
}
window.onload = scrollDiv;
</script>
<snip>
Thank you, that does the trick.
RobB wrote:
[...] Try this...
<script type="text/javascript">
function scrollDiv() { var el; if ((el = document.getElementById('MyDivId')) && ('undefined' != typeof el.scrollTop)) { el.scrollTop = 0; el.scrollTop = 5000; } }
[...]
But that presumes that the div goes all the way to the bottom of
the page...
Here's an attempt at using an automated anchor. It's a bit
rough, but I don't know enough about CSS (or perhaps even JS) to
make it work properly. See if you can make it better...
<html><head><title>play</title>
<style type="text/css">
.upper {color: #333366; background-color: #ddddff;
position: relative; height: 2000px;}
.lower {position: absolute; bottom: 0; visibility: hidden;}
.other {color: #333366; background-color: #ddddff;
position: absolute; top: 2020px; height: 2000px;
width:100%;}
</style>
<script type="text/javascript">
function hitBottom() {
// the '' seems to be needed to make x a string
var x = window.location + '';
if (x.indexOf('#') == '-1') {
window.location = window.location + '#bottom';
}
// I'd like to put an else here to just reload the page,
// but it causes an endless loop of reloading
}
</script>
</head><body>
</head><body onload="hitBottom();">
<div class="upper" style="border: 5px groove gold;">
<a href="#bottom">Here is the div</a><br>
<div class="lower"><br>
<a name="bottom">fred</a>
</div>
<br>
<div class="other">
hi
</div>
</body></html>
--
Rob
RobG wrote: RobB wrote: [...] Try this...
<script type="text/javascript">
function scrollDiv() { var el; if ((el = document.getElementById('MyDivId')) && ('undefined' != typeof el.scrollTop)) { el.scrollTop = 0; el.scrollTop = 5000; } } [...]
But that presumes that the div goes all the way to the bottom of the page...
(snip)
Not presuming anything - I think one of us misunderstood the Q. This
doesn't seem to involve scrolling the entire page, just a scrollable
(CSS overflow: auto|scroll) element. Setting refToElement.scrollTop to
a high number, larger than it would ever need to be, seems to do the
trick. The preceding 'reset' is necessary in moz, no idea why, but
otherwise the autoscroll only goes all the way to the bottom on initial
load, falling short subsequently
RobB wrote: (snip)
Not presuming anything - I think one of us misunderstood the Q. This doesn't seem to involve scrolling the entire page, just a scrollable (CSS overflow: auto|scroll) element. Setting refToElement.scrollTop to a high number, larger than it would ever need to be, seems to do the trick. The preceding 'reset' is necessary in moz, no idea why, but otherwise the autoscroll only goes all the way to the bottom on initial load, falling short subsequently
Nope, understood the question, just not your response! :-)
Your code doesn't do anything in either Mozilla or IE for me,
even though no errors are produced and as far as I can tell,
everything seems OK. Maybe my CSS is crap?
Here's what I'm working with:
<html><head><title>play</title>
<style type="text/css">
.upper {color: #333366; background-color: #ddddff;
position: relative; height: 2000px; overflow: auto;
border: 5px groove red;}
.lower {position: absolute; bottom: 0px;}
.other {color: #334433; background-color: #ddddff;
position: absolute; top: 2020px; height: 2000px;
width:100%;}
</style>
<script type="text/javascript">
function scrollDiv() {
var el = document.getElementById('MyDivId');
if ('undefined' != typeof el.scrollTop) {
el.scrollTop = '0px';
el.scrollTop = '5000px';
} else {
alert('scrollTop bzzzt');
}
}
</script>
</head><body>
</head><body>
<div class="upper" id="MyDivId">
<a href="#bottom">Link to bottom</a><br>
<button onclick="scrollDiv();">scrollDiv</button>
<div class="lower"><br>
<a name="bottom">bottom</a>
</div>
</div>
<br>
<div class="other">
other div
</div>
</body></html>
--
Rob
"RobG" <rg***@iinet.net.auau> wrote in message
news:OF*****************@news.optus.net.au... RobB wrote: (snip)
Not presuming anything - I think one of us misunderstood the Q. This doesn't seem to involve scrolling the entire page, just a scrollable (CSS overflow: auto|scroll) element. Setting refToElement.scrollTop to a high number, larger than it would ever need to be, seems to do the trick. The preceding 'reset' is necessary in moz, no idea why, but otherwise the autoscroll only goes all the way to the bottom on initial load, falling short subsequently
Nope, understood the question, just not your response! :-)
Your code doesn't do anything in either Mozilla or IE for me, even though no errors are produced and as far as I can tell, everything seems OK. Maybe my CSS is crap?
Here's what I'm working with:
<html><head><title>play</title> <style type="text/css"> .upper {color: #333366; background-color: #ddddff; position: relative; height: 2000px; overflow: auto; border: 5px groove red;} .lower {position: absolute; bottom: 0px;} .other {color: #334433; background-color: #ddddff; position: absolute; top: 2020px; height: 2000px; width:100%;} </style> <script type="text/javascript"> function scrollDiv() { var el = document.getElementById('MyDivId'); if ('undefined' != typeof el.scrollTop) { el.scrollTop = '0px'; el.scrollTop = '5000px'; } else { alert('scrollTop bzzzt'); } } </script>
</head><body> </head><body>
<div class="upper" id="MyDivId"> <a href="#bottom">Link to bottom</a><br> <button onclick="scrollDiv();">scrollDiv</button> <div class="lower"><br> <a name="bottom">bottom</a> </div> </div> <br> <div class="other"> other div </div> </body></html>
-- Rob
How does all this differ from my original method:
document.all.MyDivId.scrollTop = 5000;
Except that it does a lot of compatibility checking first? (Which I am not
too concerned about as my clients are recommended to use IE anyway - don't
ask!) This method does not work on a div.
I just thought there would be some easy 1 line command, browser
independent, to set a scroll bar to the end!
Simon Wigzell wrote:
[...] How does all this differ from my original method:
document.all.MyDivId.scrollTop = 5000;
Not greatly, my suggestion was to use a link which requires zero
JavaScript if the link to the page includes it. But it scrolls
the entire page to the anchor, which is likely not what you
wanted. I couldn't get my JS method to work reasonably anyway. Except that it does a lot of compatibility checking first? (Which I am not too concerned about as my clients are recommended to use IE anyway - don't ask!) This method does not work on a div.
I couldn't get RobB's script to work at all in any browser - but
I'm not allowed access to the security settings of IE on my
Windows box so it may be that.
It is fairly trivial to include support for non-document.all
browsers. Given the rise in support for alternatives, I think
it's reasonable to include it anyway, regardless of your
client's (?) opinion.
Using document.getElementById will work back to about IE 5.5.
Have a look at the FAQ and dynWrite:
<URL:http://www.jibbering.com/faq>
Or just include something like:
if (document.getElementById) {
var x = document.getElementById('aRef');
} else {
var x = document.all('aRef');
}
Numerous shorthand versions of the above abound in posts here.
var x;
if ( (x = document.getElementById('aRef))
|| (x = document.getElementById('aRef')) )
etc. I just thought there would be some easy 1 line command, browser independent, to set a scroll bar to the end!
Hmmm.
--
Rob
RobG wrote: RobB wrote: (snip)
Not presuming anything - I think one of us misunderstood the Q.
This doesn't seem to involve scrolling the entire page, just a
scrollable (CSS overflow: auto|scroll) element. Setting refToElement.scrollTop
to a high number, larger than it would ever need to be, seems to do
the trick. The preceding 'reset' is necessary in moz, no idea why, but otherwise the autoscroll only goes all the way to the bottom on
initial load, falling short subsequently
Nope, understood the question, just not your response! :-)
Your code doesn't do anything in either Mozilla or IE for me...
(snip)
....probably because those divs have no content to speak of. Setting CSS
overflow to 'auto' won't have any effect if there isn't any overflow,
i.e. the rendered height of the element is greater than the scroll
height of any content. Again: you seem to be fixated on scrolling the
entire page, not the contents of an embedded div element.
function scrollDiv() { var el = document.getElementById('MyDivId'); if ('undefined' != typeof el.scrollTop) { el.scrollTop = '0px'; el.scrollTop = '5000px';
(snip)
btw scroll properties are integers...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<style type="text/css">
#foo {
width: 200px;
height: 500px;
margin: 40px auto;
overflow: auto;
}
</style>
<script type="text/javascript">
function scrollDiv()
{
var el;
if (document.getElementById
&& (el = document.getElementById('foo'))
&& ('undefined' != typeof el.scrollTop))
{
el.scrollTop = 0;
el.scrollTop = 5000;
}
}
onload = scrollDiv;
</script>
</head>
<body>
<div id="foo">
<script type="text/javascript">
x = 0, y = [];
while (x++ < 40)
y.push(x + '<hr />');
document.write(y.join(''));
</script>
</div>
</body>
</html>
I may have misinterpreted the OP's question - it was clumsily posed -
but one of us is barking up the wrong subtree...
Simon Wigzell wrote: "RobG" <rg***@iinet.net.auau> wrote in message news:OF*****************@news.optus.net.au... RobB wrote: (snip)
Not presuming anything - I think one of us misunderstood the Q.
This doesn't seem to involve scrolling the entire page, just a
scrollable (CSS overflow: auto|scroll) element. Setting
refToElement.scrollTop to a high number, larger than it would ever need to be, seems to do
the trick. The preceding 'reset' is necessary in moz, no idea why, but otherwise the autoscroll only goes all the way to the bottom on
initial load, falling short subsequently
Nope, understood the question, just not your response! :-)
Your code doesn't do anything in either Mozilla or IE for me, even though no errors are produced and as far as I can tell, everything seems OK. Maybe my CSS is crap?
Here's what I'm working with:
<html><head><title>play</title> <style type="text/css"> .upper {color: #333366; background-color: #ddddff; position: relative; height: 2000px; overflow: auto; border: 5px groove red;} .lower {position: absolute; bottom: 0px;} .other {color: #334433; background-color: #ddddff; position: absolute; top: 2020px; height: 2000px; width:100%;} </style> <script type="text/javascript"> function scrollDiv() { var el = document.getElementById('MyDivId'); if ('undefined' != typeof el.scrollTop) { el.scrollTop = '0px'; el.scrollTop = '5000px'; } else { alert('scrollTop bzzzt'); } } </script>
</head><body> </head><body>
<div class="upper" id="MyDivId"> <a href="#bottom">Link to bottom</a><br> <button onclick="scrollDiv();">scrollDiv</button> <div class="lower"><br> <a name="bottom">bottom</a> </div> </div> <br> <div class="other"> other div </div> </body></html>
-- Rob
How does all this differ from my original method:
document.all.MyDivId.scrollTop = 5000;
It differs in that Element.scrollHeight may return false (understated)
values if you call this onload, presumably because of timing issues (a
small delay fixes it). The high value insures that the element will
scroll to the end.
Except that it does a lot of compatibility checking first? (Which I
am not too concerned about as my clients are recommended to use IE anyway -
don't ask!) This method does not work on a div.
You really need to learn how to communicate...what does 'This method
does not work on a div' mean? What method? What 'div'? Jeez...
I just thought there would be some easy 1 line command, browser independent, to set a scroll bar to the end!
JS doesn't do commands. A tiny script is hardly anything to get
exercised about.
<snip>> You really need to learn how to communicate...what does 'This method does not work on a div' mean? What method? What 'div'? Jeez...
If you go back to the original post I state that I have tried :
document.all.MyDivId.scrollTop = document.all.MyDivId].scrollHeight;
and it does not work with a div, but does with a text area. The guts of the
solution posated by ROB amount to:
document.all.MyDivId.scrollTop = 5000 I just thought there would be some easy 1 line command, browser independent, to set a scroll bar to the end!
JS doesn't do commands. A tiny script is hardly anything to get exercised about.
Well, I haven't found a tiny script that works yet! You'd think there would
be something like:
document.MyForm.MyDivId.ScrollBottom()
or something. Geez!
RobB wrote:
[...] Your code doesn't do anything in either Mozilla or IE for me...
(snip)
...probably because those divs have no content to speak of. Setting CSS overflow to 'auto' won't have any effect if there isn't any overflow, i.e. the rendered height of the element is greater than the scroll height of any content. Again: you seem to be fixated on scrolling the entire page, not the contents of an embedded div element.
Yup. So my understanding of CSS was somewhat lacking (as
expected). function scrollDiv() {
[...] </html>
Thanks for the working example, neat. Now if I could ever find
a use for it... I may have misinterpreted the OP's question - it was clumsily posed - but one of us is barking up the wrong subtree...
No, just unable to implement a solution that didn't scroll the
page. Thanks again for persisting. :-)
--
Rob This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mikko Ohtamaa |
last post by:
From XML specification:
The
representation of an empty element is either a start-tag immediately
followed by an end-tag, or an empty-element tag.
(This means that <foo></foo> is equal to...
|
by: Philo |
last post by:
How do I select all <div> tags except those which contain a <table> tag
somewhere within them?
Example XML:
<********************** sample input ***********************>
<txtSectionBody>...
|
by: Paul Thompson |
last post by:
When I put a <div ...> inside a <table> specification, functionality is
not there. When I put the <table> inside the <div> everything works.
Why is that?
|
by: Daniel Hansen |
last post by:
I know this must seem totally basic and stupid, but I cannot find any reference that describes how to control the spacing between <p>...</p> and
<div>...</div> blocks. When I implement these on a...
|
by: slim |
last post by:
hi again all,
i am still working on the website as mentioned in earlier threads and
have hit another snag...
http://awash.demon.co.uk/index.php
http://awash.demon.co.uk/vd.css
the php is...
|
by: Marcus Otmarsen |
last post by:
Ok, the situation is as follows:
I defined a <DIV> like:
<div id="myid" style="position: absolute; height: 10; width: 10;"><img src="images/object.gif" height=10 width=10></div>
This pane is...
|
by: Josef K. |
last post by:
Asp.net generates the following html when producing RadioButton lists:
<td><input
id="RadioButtonList_3"
type="radio"
name="MyRadioButtonList"
value="644"...
|
by: Kent Feiler |
last post by:
1. Here's some html from a W3C recommendations page.
<P>aaaaaaaaa<DIV>bbbbbbbbb</DIV><DIV>cccccccc<P>dddddddd</DIV>
2.Although I didn't think it would make any difference, I tried it
with the...
|
by: prino |
last post by:
Hi all,
I've written code (in REXX) that takes files in legacy languages (PL/I, COBOL, z/OS assembler, etc) and converts them into HTML in a format similar to what's displayed in the z/OS ISPF...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |