View Full Version : Resolved small scroll to top code throwing IE error

04-08-2009, 05:10 AM
I've implemented a custom jquery content div scroller which at first I thought was the issue. After further testing I discovered that once my page loads everything is fine but when I click my "Back to Top" link IE shows the "Exception thrown and not caught" error. I did quite a bit of digging and that error is all over the internet for multiple issues, but I wondered if I posted my link call and short javascript if anyone had any ideas?

<a href="#" onClick="backToTop(); return false">Back to Top</a>

actual js doc which creates the smooth scroll back to the top

// JavaScript Document

function backToTop() {
var x1 = x2 = x3 = 0;
var y1 = y2 = y3 = 0;

if (document.documentElement) {
x1 = document.documentElement.scrollLeft || 0;
y1 = document.documentElement.scrollTop || 0;

if (document.body) {
x2 = document.body.scrollLeft || 0;
y2 = document.body.scrollTop || 0;

x3 = window.scrollX || 0;
y3 = window.scrollY || 0;

var x = Math.max(x1, Math.max(x2, x3));
var y = Math.max(y1, Math.max(y2, y3));

window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

if (x > 0 || y > 0) {
window.setTimeout("backToTop()", 25);


The page is fine until the link is clicked and I've used this same code on other sites not running jquery and it works ok...maybe everyone will just view it in Firefox LOL :D

My custom content div scroller is running on jquery 1.3.2, and I was hoping I didn't have to implement an in-depth jquery smooth page scroller just to attempt to remove this one error. Thank you

04-09-2009, 12:57 AM
I was finally able to find a smooth page scroller that wasn't jquery driven which works with the jquery custom div scroller.