SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    scrollIntoView possible onload?

    Is it possible to use scrollIntoView onload? I know how to use it onclick, but I can not find out how to use it onload. Is it possible? And if it is, what would be the correct syntax?

    <script>
    function showIt(elID)
    {
    var el = document.getElementById(elID);
    el.scrollIntoView(true);
    }
    </script>

    <input type="button" value="Show para" onclick="showIt('pToShow');" />
    Dilster.com - Dating blog where you can find new dating tips, advices and ideas or your partner.

  2. #2
    SitePoint Evangelist
    Join Date
    Sep 2006
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An easier way (non-javascript too) would just to put a hash in your url.

    Code:
    <a href="http://www.yourdomain.com#elID">This link will scroll page to elID</a>
    elID of course being the id of the element that you want your page to automatically scroll to.

  3. #3
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I need to use it inside form action which doesn't work in ie8. Also I need to use this if user came to site from other site as first visit.
    Dilster.com - Dating blog where you can find new dating tips, advices and ideas or your partner.

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use the onload event of the body:

    <head>
    <script>
    function showIt(elID)
    {
    var el = document.getElementById(elID);
    el.scrollIntoView(true);
    }
    </script>
    </head>
    <body onload="showIt ('pToShow')">
    </body>

    In case of form submit, use the onsubmit event.
    I think the following links will help you:
    onload,
    onsubmit
    Gumape


Bookmarks

Posting Permissions

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