View Full Version : Have web page load and scroll to specific div
07-22-2011, 06:08 PM
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:
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?
07-22-2011, 06:14 PM
To do this the conventional way you should be using a URL structure like this:
07-22-2011, 06:18 PM
Amazing. Thank you Rowsdower!!!!
07-22-2011, 06:19 PM
Happy to help. And thank you for marking the thread as resolved!! :thumbsup:
Too few people bother to do that...
07-22-2011, 07:00 PM
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.
07-23-2011, 03:45 PM
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:
That should get you the best of both worlds.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.