...

View Full Version : scroll to page bottom with JS



I Am Coo Man
06-10-2003, 04:38 AM
Hi can you help me with a few simple questions? First being the one in the title.

How can I just go right to the most bottom of the page with Javascript apon l0ading of page? ALso its in an iframe if that matters but I want the Iframe to scroll to its most bottom. No fancy slow scrolling just quick go 2 bottom.

Second is auto refocus. I'm making a chat and I want it so that when I press enter the cursur automatically goes back to the chat input (just a form element) but I dunno how. Heres what I have I dont know why it doesnt work.

I have a main page and within that two iframes. In one Iframe I have this JS code...


<script language="JavaScript">
<!--
function sub_form()
{
document.form1.message.value='';
document.form1.message.focus();
}
-->
</script>

In the head tag. Then of course I have a text input called 'message' in a form called form 1 all within that same iframe. Then for activation of this code, in the body tags I have the form do this.. (still in same iframe)


<form action="page.php?" method="post" name="form1" target="chatList" onSubmit='setTimeout("sub_form()", 10);'>

Yet it doesnt refocus yet it does delete the value of the form input called 'message'

Anyone can help me to get this to work?

Thanks for any help! I greatly apreciate :)

I Am Coo Man
06-11-2003, 01:40 AM
help me please

I Am Coo Man
06-12-2003, 12:01 AM
Help me plz

brothercake
06-12-2003, 12:19 AM
Have you tried putting an anchor at the very bottom of the page, and then sending focus to it, like:

<a id="bottom"></a>

then

document.getElementById("bottom").focus();

I Am Coo Man
06-12-2003, 01:36 AM
Thx but that dont work in Opera. Cant someone just tell me what the keyword is in Javascript that scrolls the page? Can't find it.

THanks.

PS any other solutions that work in opera?

Mr J
06-12-2003, 07:07 PM
Something like this maybe?



function scrollme(){
dh=document.body.scrollHeight
ch=document.body.clientHeight
if(dh>ch){
moveme=dh-ch
window.scrollTo(0,moveme)
}
}

I Am Coo Man
06-13-2003, 06:36 PM
Thank you mucho that workz!:thumbsup: :cool: :D :) :p :thumbsup:

scriptkeeper
06-13-2003, 07:03 PM
I would like to jump in with a ? is it possible to do the same this only with an iframe?

Mr J
06-13-2003, 07:37 PM
Place this function in the page containing the iframe


function scrollme(){
dh=document.getElementById("frame1").document.body.scrollHeight
ch=document.getElementById("frame1").height
if(dh>fh){
moveme=dh-fh
frame1.window.scrollTo(0,moveme)
}
}



Where frame1 is the name of the Iframe

scriptkeeper
06-13-2003, 07:57 PM
great it works but i cant get it to scroll back is this wrong

datamain.window.scrollBy(-10,0)

Mr J
06-13-2003, 08:24 PM
scrollBy(X,Y)



Try this

datamain.window.scrollBy(0,-10)





To scroll it back to the top you need


datamain.window.scrollTo(0,0)

scriptkeeper
06-13-2003, 08:49 PM
I want it to scroll a certain amount each click from left to right thats why im using scrollBy()!

Mr J
06-13-2003, 08:55 PM
I see.


Is the document width wider than the iframe?

Mr J
06-13-2003, 09:02 PM
Try this.

In the Iframe page:

<table border="1" width="1800">
<tr>
<td width="600" bgcolor="0000FF">&nbsp;</td>
<td width="600" bgcolor="00FF00">&nbsp;</td>
<td width="600" bgcolor="FF0000">&nbsp;</td>
</tr>
</table>


In the page containing the Iframe:

<script>
function scrollme2(){
document.frame1.window.scrollBy(100,0)
}
</script>

<a href="#null" onclick="scrollme2()">Scroll Right</a>

scriptkeeper
06-13-2003, 11:10 PM
Yes that is what I already know how can I make it scroll left!

Garadon
06-14-2003, 12:01 AM
document.frame1.window.scrollBy(-100,0);
scrolls left or at least it does for me.

scriptkeeper
06-14-2003, 01:06 AM
cool I have been using this

frame1.window.scrollBy(-100,0);

Ill try that later!

Mr J
06-14-2003, 08:44 AM
Amend the function and the links as follows


function scrollme2(dir){
document.frame1.window.scrollBy(dir,0)
}




<P><a href="#null" onclick="scrollme2(100)">Scroll Right</a>
<P><a href="#null" onclick="scrollme2(-100)">Scroll Left</a>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum