javascript position page

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

    javascript position page

    set scroll position in javascript.

    Is there a way to do this without using document.locati on, example.

    document.locati on = "#gohere"


    <a name="gohere">
  • Stuart Palmer

    #2
    Re: javascript position page

    just use an <a href> tag, no need for JS here

    <a href="pagename. html#gohere">Li nk</a>

    Stu

    "bigbinc" <bigbinc@hotmai l.com> wrote in message
    news:d1b33313.0 308250915.2ed3c 576@posting.goo gle.com...[color=blue]
    > set scroll position in javascript.
    >
    > Is there a way to do this without using document.locati on, example.
    >
    > document.locati on = "#gohere"
    >
    >
    > <a name="gohere">[/color]


    Comment

    • Fred Basset

      #3
      Re: javascript position page

      In IE only, you can use the scrollIntoView method.

      object.scrollIn toView()

      You can also pass an argument to specify scrolling the element to the
      top or bottom of the page. For more information, see ...

      Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

      intoview.asp

      Not ideal if you are publishing to the internet, but if it's an intranet
      or controlled environment then you could use it.

      Fred Basset
      fred.basset@who syourdaddy.com

      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Dom Leonard

        #4
        Re: javascript position page

        bigbinc wrote:[color=blue]
        > set scroll position in javascript.
        >
        > Is there a way to do this without using document.locati on, example.
        >
        > document.locati on = "#gohere"
        >
        >
        > <a name="gohere">[/color]

        Using a function taking the name of an anchor:
        function pageXY( el)
        {
        var XY={x:0, y:0};
        for( var node = el; node; node=node.offse tParent)
        { XY.x += node.offsetLeft ;
        XY.y += node.offsetTop;
        }
        return XY;
        }
        function gotoName( name)
        {
        var anchors, anchor, XY;
        anchors=documen t.anchors;
        anchor=anchors[name];

        if(!anchor) // IE sucks
        { for( var i = 0; i < anchors.length; ++i)
        { if(anchors[i].name==name)
        { anchor = anchors[i];
        break;
        }
        }
        }
        if(!anchor)
        { if( document.getEle mentById)
        anchor=document .getElementById (name);
        else if( document.all) // untested
        anchor=document .all[name];
        }
        if(anchor)
        { XY = pageXY(anchor);
        window.scrollTo (XY.x, XY.y);
        }
        }

        ----

        This contains some "paranoid" code in that it searches for an element
        with the same id as the supplied name if it cannot find a matching
        anchor, and makes no attempt to fix broken positioned offset chains as
        may be encountered for anchors within tables using padding and borders,
        or anchors within relatively positioned elements under MSIE.

        Found in testing:
        * IE 6 doesn't appear to implement document.anchor s as an HTMLCollection
        and didn't return a named anchor property,
        * As I understand it, document.getEle mentsByTagName( "A") should return a
        nodeList without named lookup (part of the NamedNodeMap and
        HTMLCollection interfaces). Not included in above code, Mozilla returned
        an HTMLCollection, Opera 7 a "nodeList" with named lookup support and
        IE6 some kind of index collection *with* named lookup.

        For trivial comment, document.locati on was deprecated in favor of
        window.location as far back as javascript 1.3, although all three
        browsers tested seem to support it.

        HTH
        Dom


        Comment

        Working...