Return to Snippet

Revision: 59133
at August 19, 2012 20:06 by chrisguiblin

Initial Code
<script languate="javascript" type="text/javascript">
	//Get the values from the url variable id
	//(getUrlVars Code URL:
	function getUrlVars()
		var vars = {};
		var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value){
			vars[key] = value;});
		return vars;
	//scroll to the specific div, assuming each div is named "div_(number)"
	function scrollToID() 
		document.getElementById("div_" + id).scrollIntoView();
	var id = getUrlVars()["id"];	

Initial URL

Initial Description
This code assumes a page is populated with divs with ids div_1, div_2, div_3 etc etc etc...

Some quick php to create 200 divs numbered as above:

			 "	DIV ".$i.

To test the code, add an id to the url so its something like this (assuming urlVars.php is the name of the page):


Play around with the id number to test.

Initial Title
Scroll to specific div using a variable from the URL on page load

Initial Tags

Initial Language