Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    scroll to page bottom with JS

    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
    Last edited by I Am Coo Man; 06-10-2003 at 04:42 AM.

  • #2
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    help me please

  • #3
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Help me plz

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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();
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #5
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Something like this maybe?



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

  • #7
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you mucho that workz!
    Last edited by I Am Coo Man; 06-13-2003 at 06:42 PM.

  • #8
    Regular Coder
    Join Date
    Apr 2003
    Location
    Northern California
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would like to jump in with a ? is it possible to do the same this only with an iframe?

  • #9
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    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

  • #10
    Regular Coder
    Join Date
    Apr 2003
    Location
    Northern California
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts
    great it works but i cant get it to scroll back is this wrong

    datamain.window.scrollBy(-10,0)

  • #11
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    scrollBy(X,Y)



    Try this

    datamain.window.scrollBy(0,-10)





    To scroll it back to the top you need


    datamain.window.scrollTo(0,0)
    Last edited by Mr J; 06-13-2003 at 08:26 PM.

  • #12
    Regular Coder
    Join Date
    Apr 2003
    Location
    Northern California
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I want it to scroll a certain amount each click from left to right thats why im using scrollBy()!

  • #13
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    I see.


    Is the document width wider than the iframe?

  • #14
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    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>

  • #15
    Regular Coder
    Join Date
    Apr 2003
    Location
    Northern California
    Posts
    169
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes that is what I already know how can I make it scroll left!


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •