By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,568 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,568 IT Pros & Developers. It's quick & easy.

return scrollbar to position-not working in opera/ff

P: n/a
I have been using the following script to return a scrollbar to the position
it was in before the data was posted. It works in ie but not in firefox.

Thanks,

R.

<script type="text/javascript">
window.onload = function(){
var strCook = document.cookie;
if(strCook.indexOf("!~")!=0){
var intS = strCook.indexOf("!~");
var intE = strCook.indexOf("~!");
var strPos = strCook.substring(intS+2,intE);
document.getElementById("menu_holder_inside").scro llTop = strPos;
}
}
function SetDivPosition(){
var intY = document.getElementById("menu_holder_inside").scro llTop;
// document.title = intY;
document.cookie = "yPos=!~" + intY + "~!";
}
</script>

and on the div

<div id="menu_holder_inside" onscroll="SetDivPosition()">

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Sep 27 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Ross a écrit :
I have been using the following script to return a scrollbar to the position
it was in before the data was posted. It works in ie but not in firefox.

Thanks,

R.

<script type="text/javascript">
window.onload = function(){
Your function should execute on the load event on the body, not on the
window. The window may be created, but the DOM tree (with all its
elements, images, structure, headings, etc.) might not.

var strCook = document.cookie;
if(strCook.indexOf("!~")!=0){
var intS = strCook.indexOf("!~");
var intE = strCook.indexOf("~!");
var strPos = strCook.substring(intS+2,intE);
document.getElementById("menu_holder_inside").scro llTop = strPos;
and here, you're querying for an object which may not have been yet
parsed, rendered in the document content.
}
}
function SetDivPosition(){
var intY = document.getElementById("menu_holder_inside").scro llTop;
// document.title = intY;
document.cookie = "yPos=!~" + intY + "~!";
}
</script>

and on the div

<div id="menu_holder_inside" onscroll="SetDivPosition()">


I see nothing wrong with your code. Personally, I would ditch that
function, cookie handling, string parsing, value storing, etc.., and
then just resort to scrollIntoView() instead. Something like this:

<body
onload="document.getElementById('menu_holder_insid e').scrollIntoView(true);"
....>

scrollIntoView is supported by MSIE 5+ and Mozilla 1.5+, Firefox 1.x, NS
7.x, etc.

Gérard
--
remove blah to email me
Sep 28 '05 #2

P: n/a
Gérard Talbot a écrit :
Ross a écrit :
I have been using the following script to return a scrollbar to the
position it was in before the data was posted. It works in ie but not
in firefox.

Thanks,

R.

<script type="text/javascript">
window.onload = function(){

Your function should execute on the load event on the body, not on the
window. The window may be created, but the DOM tree (with all its
elements, images, structure, headings, etc.) might not.

var strCook = document.cookie;
if(strCook.indexOf("!~")!=0){
var intS = strCook.indexOf("!~");
var intE = strCook.indexOf("~!");
var strPos = strCook.substring(intS+2,intE);
document.getElementById("menu_holder_inside").scro llTop =
strPos;

and here, you're querying for an object which may not have been yet
parsed, rendered in the document content.
}
}
function SetDivPosition(){
var intY =
document.getElementById("menu_holder_inside").scro llTop;
// document.title = intY;
document.cookie = "yPos=!~" + intY + "~!";
}
</script>

and on the div

<div id="menu_holder_inside" onscroll="SetDivPosition()">

I see nothing wrong with your code.


[snipped]
Forget that part on scrollIntoView().

I think your code is correct except it should be the load event on the
body node, not on the window (asychronous events). Window load event
always fires before the body load event since their content and tasks
involved are different.

Gérard
--
remove blah to email me
Sep 28 '05 #3

P: n/a
Ross wrote:
I have been using the following script to return a scrollbar to the position
it was in before the data was posted. It works in ie but not in firefox.


This link will explain your problem with 'onscroll':

<URL:http://www.quirksmode.org/js/events_compinfo.html>

Onscroll is a method of the window object, it is not a W3C standard and
belongs to DOM Level 0 (i.e. inherited from pre-W3C browsers).

<URL:http://www.mozilla.org/docs/dom/domref/dom_window_ref72.html#1018974>

This link deals with the issue with scrollTop:

<URL:http://www.quirksmode.org/viewport/compatibility.html>

All other browsers use pageYOffset, IE 6 uses
document.documentElement.scrollTop (in strict mode), for all other IEs
and 6 in quirksmode use document.body.scrollTop.

You need to feature test (a cross-browser function is provided at the
link to determine how much the page has scrolled - search for scrollTop
or pageYOffset).

[...]
--
Rob
Sep 28 '05 #4

P: n/a
RobG a écrit :
Ross wrote:
I have been using the following script to return a scrollbar to the
position it was in before the data was posted. It works in ie but not
in firefox.

You snipped important chuncks of code from the OP. Here it is:
{
<script type="text/javascript">
window.onload = function(){
var strCook = document.cookie;
if(strCook.indexOf("!~")!=0){
var intS = strCook.indexOf("!~");
var intE = strCook.indexOf("~!");
var strPos = strCook.substring(intS+2,intE);
document.getElementById("menu_holder_inside").scro llTop = strPos;
}
}
function SetDivPosition(){
var intY = document.getElementById("menu_holder_inside").scro llTop;
// document.title = intY;
document.cookie = "yPos=!~" + intY + "~!";
}
</script>

and on the div

<div id="menu_holder_inside" onscroll="SetDivPosition()">

}

His function name is SetDivPosition. His function name is not
SetPagePosition nor SetWindowPosition or something like that.


This link will explain your problem with 'onscroll':

<URL:http://www.quirksmode.org/js/events_compinfo.html>

Onscroll is a method of the window object, it is not a W3C standard
DOM 3 Events interface compliant, scroll event for element:
"scroll
A document view or an element has been scrolled. The scroll occured
before the dispatch of this event type."
http://www.w3.org/TR/2003/NOTE-DOM-L...l#event-scroll

and belongs to DOM Level 0 (i.e. inherited from pre-W3C browsers).

MSIE 6, Mozilla 1.x, Firefox 1.x, NS 7.x and a bunch of other browsers
do support the scroll event for scrollable elements like a <div>.

<URL:http://www.mozilla.org/docs/dom/domref/dom_window_ref72.html#1018974>

How about testing this file then?:

http://www.mozilla.org/docs/dom/domr...p.html#Example



This link deals with the issue with scrollTop:

<URL:http://www.quirksmode.org/viewport/compatibility.html>

All other browsers use pageYOffset,

pageYOffset is a property of the window object (NS 4+, Mozilla 1.x,
Firefox 1.x, Opera 6+, etc.)
pageYOffset is not a property of the scrollable elements like a <div>.
IE 6 uses document.documentElement.scrollTop (in strict mode), for all other IEs
and 6 in quirksmode use document.body.scrollTop.

That's for a document scroll-view. What about a div? That is what the OP
asked..., no?
You need to feature test (a cross-browser function is provided at the
link to determine how much the page has scrolled - search for scrollTop
or pageYOffset).

[...]


http://developer.mozilla.org/en/docs...lTop#scrollTop

http://www.gtalbot.org/BugzillaSecti...roperties.html

The OP is right regarding Opera 7+. Opera does not support registering a
scroll event listener to a scrollable element. I.e.:
ElementReference.addEventListener("scroll", functionName, false);
is not supported for Opera 7+. But DOM 3 Events compliant browsers
support the scroll event for elements.

http://www.w3.org/TR/2003/NOTE-DOM-L...l#event-scroll

And pretty much all modern browsers support MSIE's DHTML object model.

Gérard
--
remove blah to email me
Sep 29 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.