Hi,
i was also looking for such a feature and based on the script i created a solution for firefox and my css based pages.
1) the js-script
Code:
function POSREMsetCookie(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 POSREMgetCookie(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 POSREMsaveScroll() {
var elem=document.getElementById('maincontent')
if (!elem) return;
var scroll = (window.scrollTo) ? 1 : 0;
if (!scroll) return;
var now = new Date();
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
var x = (elem) ? elem.scrollLeft : pageXOffset;
var y = (elem) ? elem.scrollTop : pageYOffset;
POSREMsetCookie("xy", x + "_" + y, now);
}
function POSREMloadScroll() {
var elem=document.getElementById('maincontent')
if (!elem) return;
var scroll = (window.scrollTo) ? 1 : 0;
if (!scroll) return;
var xy = POSREMgetCookie("xy");
if (!xy) return;
var ar = xy.split("_");
if (ar.length == 2){
elem.scrollLeft=ar[0] ;
elem.scrollTop=ar[1] ;
}
}
==> gave an POSREM prefix to be more significant
==> at the moment it is hardcoded to use an element with the id "maincontent"
==> script is located in an separate file PositionRemember.js
2)
The Head-section becomes the scriptinclusion
HTML Code:
<script type="text/javascript" src="./js/PositionRemember.js"></script>
3)
The Body-Tag becomes the onLoad and onUnload Functions
HTML Code:
<BODY onLoad="POSREMloadScroll()" onUnload="POSREMsaveScroll()">
4)
and my "Maincontent"-Area is declared with
HTML Code:
<div id="maincontent" class="main" style="overflow:scroll">
class main is defined as
Code:
.main {
position:fixed ;
border:0px ;
top:92px ;
left:146px ;
/*width:73em;*/
width:952px;
/*
height:40em;
*/
height:600px;
/*
background: #ececec url(background.jpg) repeat-x ;
background: #ececec ;
background-color: #eceded ;
*/
background-color: white ;
color: black ;
font-size: 12px ;
font-family: Arial, Helvetica, Geneva, Swiss, SunSans-Regular, sans-serif ;
z-index: 1;
}
Summary
due to the fixed width and height in the class definition and the overflow:scroll declaration the page was ugly to use when the lists where long. Now it returns to the last position. Another effect: the usage of id="maincontent" controls wich pages are POSREM-enabled.
At the moment i think it could be an open problem due to the saving of
the position in an cookie with the name xy wich isnt significant enough
to use it in multiple pages (and users use multiple browser tabs). But now
its friday and i think by myself this is a good thing for the next week.
Good luck
Michael
Bookmarks