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.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Location
    Toronto, ON
    Posts
    102
    Thanks
    12
    Thanked 1 Time in 1 Post

    Have web page load and scroll to specific div

    Hi guys,

    Hopefully I have posted this in the correct section.

    My website has lists of information. Each piece of data is in it's own div, and each has a unique id. ex:

    Code:
    <div id="2220">
    </div>
    <div id="2221">
    </div>
    etc.....
    I want to be able to create external links like: http://www.mysite.com?id=2221

    And when someone clicks on the site the page will automatically scroll down to the div that has the id 2221.

    Is this possible?
    Last edited by inchecksolution; 07-22-2011 at 05:58 PM.

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Using the URL structure you are showing us you could do this with javascript (which I would argue is a bad thing to do).

    To do this the conventional way you should be using a URL structure like this:

    http://www.mysite.com/#2221
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • Users who have thanked Rowsdower! for this post:

    inchecksolution (07-22-2011)

  • #3
    Regular Coder
    Join Date
    Jul 2011
    Location
    Toronto, ON
    Posts
    102
    Thanks
    12
    Thanked 1 Time in 1 Post
    Amazing. Thank you Rowsdower!!!!

  • #4
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Happy to help. And thank you for marking the thread as resolved!!

    Too few people bother to do that...
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #5
    Regular Coder
    Join Date
    Jul 2011
    Location
    Toronto, ON
    Posts
    102
    Thanks
    12
    Thanked 1 Time in 1 Post
    lol it has now been moved to unresolved haha. It has brought up another question.

    It is working and scrolling to the proper div using http://www.mysite.com/#2221 BUT is there a way I can assign the 2221 (or whatever the number happens to be) to a php variable? I want to be able to use that number in a mysql query. I don't know any other method except the $_REQUEST method but I assume that it won't work in this case.

    THANKS!

  • #6
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    The server never sees the part after the hash symbol so you can't directly access anything from the hash portion. You can use a standard $_GET type of URL as the base like in your initial post and then combine it with the hash thingy like so:

    http://www.mysite.com?id=2221#2221

    That should get you the best of both worlds.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting


  •  

    Posting Permissions

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