monkeypuppet
03-27-2009, 04:21 AM
Hi, been looking for a solution for days.
I want the browser to remember the scroll position and recall it when the user changes pages or refreshes.
I got this script working in Firefox but neither IE6 or IE7 ...
http://www.webreference.com/js/tips/991203.html
<SCRIPT LANGUAGE="JavaScript">
<!--
var db = (document.body) ? 1 : 0;
var scroll = (window.scrollTo) ? 1 : 0;
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
document.cookie = curCookie;
}
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else {
begin += 2;
}
var end = document.cookie.indexOf(";", begin);
if (end == -1) end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}
function saveScroll() {
if (!scroll) return;
var now = new Date();
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
var x = (db) ? document.body.scrollLeft : pageXOffset;
var y = (db) ? document.body.scrollTop : pageYOffset;
setCookie("xy", x + "_" + y, now);
}
function loadScroll() {
if (!scroll) return;
var xy = getCookie("xy");
if (!xy) return;
var ar = xy.split("_");
if (ar.length == 2) scrollTo(parseInt(ar[0]), parseInt(ar[1]));
}
// -->
</SCRIPT>
<BODY onLoad="loadScroll()" onUnload="saveScroll()">
This is my index.php -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<SCRIPT LANGUAGE="JavaScript">
<!--
var db = (document.body) ? 1 : 0;
var scroll = (window.scrollTo) ? 1 : 0;
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
document.cookie = curCookie;
}
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else {
begin += 2;
}
var end = document.cookie.indexOf(";", begin);
if (end == -1) end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}
function saveScroll() {
if (!scroll) return;
var now = new Date();
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
var x = (db) ? document.body.scrollLeft : pageXOffset;
var y = (db) ? document.body.scrollTop : pageYOffset;
setCookie("xy", x + "_" + y, now);
}
function loadScroll() {
if (!scroll) return;
var xy = getCookie("xy");
if (!xy) return;
var ar = xy.split("_");
if (ar.length == 2) scrollTo(parseInt(ar[0]), parseInt(ar[1]));
}
// -->
</SCRIPT>
<!--[if lte IE 6]>
<script type="text/javascript" src="supersleight-min.js"></script>
<![endif]-->
<!--[if lte IE 6]>
<link href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/ieonly.css" rel="stylesheet" type="text/css" />
<![endif]-->
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/template_css.css" rel="stylesheet" type="text/css" />
</head>
<BODY onLoad="loadScroll()" onUnload="saveScroll()">
<div id="supercontainer">
<div id="banner"></div>
<div id="middlecontainer">
<div id="innercontainer">
<div id="topcontainer">
<div id="leftcontainer">
<div id="menucontainer">
<div id="menu"><jdoc:include type="modules" name="user3" /></div>
</div>
</div>
<div id="rightcontainer">
<div id="contenttop"></div>
<div id="contentmiddle"><jdoc:include type="modules" name="user4" /></div>
<div id="contentbase"></div>
</div>
</div>
<div id="subbottomcontainer"">
<div id="productcontainertop"></div>
<div id="productcontainermiddle"><jdoc:include type="component" style="xhtml" /></div>
<div id="productcontainerbottom"></div>
</div>
</div>
</div>
<div id="bottomcontainer">
<div id="copy">
© A site 2009 <br />Site by  <a href="http://www.site.com/">Site</a>
</div>
</div>
</div>
</body>
</html>
If anyone could help me, it would be very appreciated.
I want the browser to remember the scroll position and recall it when the user changes pages or refreshes.
I got this script working in Firefox but neither IE6 or IE7 ...
http://www.webreference.com/js/tips/991203.html
<SCRIPT LANGUAGE="JavaScript">
<!--
var db = (document.body) ? 1 : 0;
var scroll = (window.scrollTo) ? 1 : 0;
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
document.cookie = curCookie;
}
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else {
begin += 2;
}
var end = document.cookie.indexOf(";", begin);
if (end == -1) end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}
function saveScroll() {
if (!scroll) return;
var now = new Date();
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
var x = (db) ? document.body.scrollLeft : pageXOffset;
var y = (db) ? document.body.scrollTop : pageYOffset;
setCookie("xy", x + "_" + y, now);
}
function loadScroll() {
if (!scroll) return;
var xy = getCookie("xy");
if (!xy) return;
var ar = xy.split("_");
if (ar.length == 2) scrollTo(parseInt(ar[0]), parseInt(ar[1]));
}
// -->
</SCRIPT>
<BODY onLoad="loadScroll()" onUnload="saveScroll()">
This is my index.php -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<SCRIPT LANGUAGE="JavaScript">
<!--
var db = (document.body) ? 1 : 0;
var scroll = (window.scrollTo) ? 1 : 0;
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
document.cookie = curCookie;
}
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else {
begin += 2;
}
var end = document.cookie.indexOf(";", begin);
if (end == -1) end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}
function saveScroll() {
if (!scroll) return;
var now = new Date();
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
var x = (db) ? document.body.scrollLeft : pageXOffset;
var y = (db) ? document.body.scrollTop : pageYOffset;
setCookie("xy", x + "_" + y, now);
}
function loadScroll() {
if (!scroll) return;
var xy = getCookie("xy");
if (!xy) return;
var ar = xy.split("_");
if (ar.length == 2) scrollTo(parseInt(ar[0]), parseInt(ar[1]));
}
// -->
</SCRIPT>
<!--[if lte IE 6]>
<script type="text/javascript" src="supersleight-min.js"></script>
<![endif]-->
<!--[if lte IE 6]>
<link href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/ieonly.css" rel="stylesheet" type="text/css" />
<![endif]-->
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/template_css.css" rel="stylesheet" type="text/css" />
</head>
<BODY onLoad="loadScroll()" onUnload="saveScroll()">
<div id="supercontainer">
<div id="banner"></div>
<div id="middlecontainer">
<div id="innercontainer">
<div id="topcontainer">
<div id="leftcontainer">
<div id="menucontainer">
<div id="menu"><jdoc:include type="modules" name="user3" /></div>
</div>
</div>
<div id="rightcontainer">
<div id="contenttop"></div>
<div id="contentmiddle"><jdoc:include type="modules" name="user4" /></div>
<div id="contentbase"></div>
</div>
</div>
<div id="subbottomcontainer"">
<div id="productcontainertop"></div>
<div id="productcontainermiddle"><jdoc:include type="component" style="xhtml" /></div>
<div id="productcontainerbottom"></div>
</div>
</div>
</div>
<div id="bottomcontainer">
<div id="copy">
© A site 2009 <br />Site by  <a href="http://www.site.com/">Site</a>
</div>
</div>
</div>
</body>
</html>
If anyone could help me, it would be very appreciated.