click makes page scroll far right

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • anna

    click makes page scroll far right

    Is it possible to have a javascript function which can scroll a page
    to the far right when a link is clicked? Any code examples available?

    TIA,
    Anna
  • mscir

    #2
    Re: click makes page scroll far right

    anna wrote:
    [color=blue]
    > Is it possible to have a javascript function which can scroll a page
    > to the far right when a link is clicked? Any code examples available?
    >
    > TIA,
    > Anna[/color]

    Hi Anna,

    I'd look at this approach:

    function doit(direction) {
    if (direction=='r' )
    window.scroll(7 00,1) //modify 1st number to change x position
    if (direction=='l' )
    window.scroll(0 ,1) //modify 1st number to change x position
    }

    <table border="1" cellspacing="1" width="1400">
    <tr>
    <td width="222">
    <input type="button" value="Right" onclick="doit(' r')">
    </td>
    <td width="222">&nb sp;</td>
    <td width="222">&nb sp;</td>
    <td width="222">&nb sp;</td>
    <td width="222">&nb sp;</td>
    <td width="222">&nb sp;</td>
    <td width="222">&nb sp;</td>
    </tr>
    <tr>
    <td width="222">&nb sp;</td>
    <td width="222">&nb sp;</td>
    <td width="222">&nb sp;</td>
    <td width="222">&nb sp;</td>
    <td width="222">&nb sp;</td>
    <td width="222">&nb sp;</td>
    <td width="222">
    <input type="button" value="Left" onclick="doit(' l')">
    </td>
    </tr>
    </table>

    Comment

    • mscir

      #3
      Re: click makes page scroll far right

      anna wrote:
      [color=blue]
      > Is it possible to have a javascript function which can scroll a page
      > to the far right when a link is clicked? Any code examples available?
      >
      > TIA,
      > Anna[/color]

      Code example here:

      The W3Schools online code editor allows you to edit code and view the result in your browser


      Comment

      • anna

        #4
        Re: click makes page scroll far right

        I tried the examples and it works fine with input type=button but
        doesn't work with type=image.

        Any way to make it work? Using the image look less clunky.

        <input type="button" value=">>" onClick="alignR ight();"> //this works

        <input type="image" src="/icons/redarrow.gif" onClick="alignR ight();">
        //rather have this work

        Comment

        • anna

          #5
          Re: [SOLUTION] click makes page scroll far right

          What I ended up doing and it works for browsers NN4, NN7, and IE6.

          <a href="javascrip t:window.scroll To(1000,0)"><im g
          src="/icons/redarrow.gif" border=0 alt="Scroll right"></a>

          Comment

          • anna

            #6
            Re: click makes page scroll far right

            SOLUTION:


            What I ended up doing and it works for browsers NN4, NN7, and IE6.

            <a href="javascrip t:window.scroll To(1000,0)"><im g
            src="/icons/redarrow.gif" border=0 alt="Scroll right"></a>

            Comment

            • anna

              #7
              Re: click makes page scroll far right

              FOLLOWUP


              if (navigator.appN ame.indexOf("Ne tscape") != -1 &&
              parseFloat(navi gator.appVersio n) < 5 ) {
              if (document.width > window.innerWid th) {
              document.write( '<a
              href="javascrip t:window.scroll To(1000,window. pageYOffset)">< img
              src="/icons/redarrow.gif" border=0 alt="Scroll right"><img
              src="/icons/redarrow.gif" border=0 alt="Scroll right"></a>');
              }
              } else {
              if (document.body. scrollWidth > document.body.c lientWidth) {
              document.write( '<a
              href="javascrip t:window.scroll To(1000,documen t.body.scrollTo p)"><img
              src="/icons/redarrow.gif" border=0 alt="Scroll right"><img
              src="/icons/redarrow.gif" border=0 alt="Scroll right"></a>');
              }
              }

              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: click makes page scroll far right

                anna wrote:
                [color=blue]
                > FOLLOWUP[/color]

                Do you really know what a followup is and what medium you are using?

                <http://www.faqs.org/faqs/usenet/posting-rules/part1/>
                [color=blue]
                > if (navigator.appN ame.indexOf("Ne tscape") != -1 &&
                > parseFloat(navi gator.appVersio n) < 5 ) {[/color]

                Nonsense. <http://pointedears.de. vu/scripts/test/whatami>

                Better:

                if (typeof document.width != "undefined"
                && typeof document.innerW idth != "undefined" )
                {
                [color=blue]
                > if (document.width > window.innerWid th) {
                > document.write( '<a
                > href="javascrip t:window.scroll To(1000,window. pageYOffset)">< img[/color]
                ^^^^^^^^^^^^
                Nonsense. <http://jibbering.com/faq/#FAQ4_24>

                Better:

                if (document.width > window.innerWid th) {
                document.write(
                '<a
                + ' href="javascrip t:void(window.s crollTo(1000,wi ndow.pageYOffse t))"'
                + ' onclick="window .scrollTo(1000, window.pageYOff set); return false"'
                + '><img ...');
                [color=blue]
                > src="/icons/redarrow.gif" border=0 alt="Scroll right"><img
                > src="/icons/redarrow.gif" border=0 alt="Scroll right"></a>');[/color]

                This will not work as supposed if you provide only one link with two images.
                [color=blue]
                > }
                > } else {
                > if (document.body. scrollWidth > document.body.c lientWidth) {[/color]

                Again you did not test for those host objects and their properties before
                accessing them. See above.
                [color=blue]
                > document.write( '<a
                > href="javascrip t:window.scroll To(1000,documen t.body.scrollTo p)"><img[/color]

                See above.
                [color=blue]
                > src="/icons/redarrow.gif" border=0 alt="Scroll right"><img
                > src="/icons/redarrow.gif" border=0 alt="Scroll right"></a>');[/color]

                See above.
                [color=blue]
                > }
                > }[/color]


                PointedEars

                Comment

                Working...