View Full Version : Divs in place of frames -- scrollbar never resets

07-06-2011, 06:42 AM
1) Script Title: Dynamic Ajax Content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem: So I'm using this script for my nav to load each section of my site into a "content" div, obviously like a php include. The page was originally all seperate php docs but now that I've added streaming audio I wanted an alternative to having to switch to a frame-based layout. The script works great but if the div is scrolled any % down from the top, when another link in the nav is clicked the div remains at that scroll point. My initial ideas have been with anchors and auto-scrolling javascripts but I can't seem to cook up an approach that works. Perhaps an augmentation to the existing ajax content script? Any ideas out there?

If seeing the problem in action is necessary I'll post the URL.


07-07-2011, 02:23 AM
Find this section in the script:

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))

Replace it with:

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
document.getElementById(containerid).innerHTML='<div style="width:2000px;height:2000px;">&nbsp;</div>';
document.getElementById(containerid).scrollTop = 0;

Just make sure that the dimensions:


are higher than tallest content page you might load and wider than the widest one.

07-07-2011, 06:29 AM

Slick. Working great! I really appreciate the help!