Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > return scrollbar to position-not working in opera/ff

Reply
Thread Tools

return scrollbar to position-not working in opera/ff

 
 
Ross
Guest
Posts: n/a
 
      09-27-2005
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
 
Reply With Quote
 
 
 
 
Gérard Talbot
Guest
Posts: n/a
 
      09-28-2005
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
 
Reply With Quote
 
 
 
 
Gérard Talbot
Guest
Posts: n/a
 
      09-28-2005
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
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      09-28-2005
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
 
Reply With Quote
 
Gérard Talbot
Guest
Posts: n/a
 
      09-29-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript scrollbar not working in hidden <DIV>s Sura Javascript 0 06-22-2009 07:10 PM
Tkinter Scrollbar not working Dustan Python 8 01-03-2006 11:12 PM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
ScrollBar? Does it exist just WEB ScrollBar Control? Alex ASP .Net Web Controls 1 04-04-2004 12:44 AM
Return a return value from Perl to Javascript PvdK Perl 0 07-24-2003 09:20 AM



Advertisments