PDA

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



brianfitzy
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.

Thanks!

jscheuer1
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))
document.getElementById(containerid).innerHTML=page_request.responseText
}

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;
document.getElementById(containerid).innerHTML=page_request.responseText;
}
}

Just make sure that the dimensions:


style="width:2000px;height:2000px;"

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

brianfitzy
07-07-2011, 06:29 AM
John,

Slick. Working great! I really appreciate the help!