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

document.body.scroll does not work in Firefox

P: n/a
sam
Hi all,

I am using documnet.body.scroll to disable the window scroll bar. This
works in IE only and not other browsers.

Can any one tell me if there is any such method which is cross browser
compatible.

Thanks,
sam

Jun 5 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
sam said the following on 6/5/2006 6:11 PM:
Hi all,

I am using documnet.body.scroll to disable the window scroll bar.
Really? Why are you trying to do something so anti-user friendly?
This works in IE only and not other browsers.
That's generally the way IE only code works.
Can any one tell me if there is any such method which is cross browser
compatible.


To do what? Stop a user from scrolling a page? overflow:hidden

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 5 '06 #2

P: n/a
sam

Thats our product design, I have no choice to change the app design. To
be more clear.
I am trying to disable the browser scroll bar when ever a popup shows
up so that only popup is accessible. I tried using overflow: hidden
but it does not do what is required.
The problem with overflow: hidden.
1) I have alenghty page, I scroll half way down and open a popup and my
popup is centered in the viewport, and now I should be able to disable
the scroll there so that the content in main window is visible but not
accessbile.

when i use overflow: hidden it always jumps to the top and picks that
area and disappears the scroll bar, in which process i cannot see my
popup which is struck far below and also the content which I was
supposed.
I hope I am not too confusing.
Thanks
sam

Randy Webb wrote:
sam said the following on 6/5/2006 6:11 PM:
Hi all,

I am using documnet.body.scroll to disable the window scroll bar.


Really? Why are you trying to do something so anti-user friendly?
This works in IE only and not other browsers.


That's generally the way IE only code works.
Can any one tell me if there is any such method which is cross browser
compatible.


To do what? Stop a user from scrolling a page? overflow:hidden

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Jun 5 '06 #3

P: n/a
sam said the following on 6/5/2006 7:19 PM:
Thats our product design, I have no choice to change the app design. To
be more clear.
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?

Please don't top-post :)
I am trying to disable the browser scroll bar when ever a popup shows
up so that only popup is accessible. I tried using overflow: hidden
but it does not do what is required.
Ahh, now I think I understand. You are using an in-window dHTML pop-up
rather than the typical pop-up caused by window.open
The problem with overflow: hidden.
1) I have alenghty page, I scroll half way down and open a popup and my
popup is centered in the viewport, and now I should be able to disable
the scroll there so that the content in main window is visible but not
accessbile.


Find the top and left of your popup, use the window.onscroll to know
when the document gets scrolled, then use window.scrollTo to scroll back
to where you started.

You have to set a flag when the popup is displayed. When the window gets
scrolled, you check that flag. If a popup is showing, you don't allow
the scroll. If it is not showing, then you allow the scrolling.
var stopScroll = false;
var popupTop = 0;
window.onscroll = stopScrolling

function stopScrolling(){
if (stopScroll){
window.scrollTo(0,popupTop)
}
}

function showPopup(){
stopScroll = true;
popupTop = XXX
//XXX would be the top position of the
//popup window.

//rest of popup code here
}

function hidePopup(){
stopScroll = false;
//code here to hide the popup
}

That is a start, it will take more than that to do what you need to do
but it's a start.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 6 '06 #4

P: n/a
sam wrote:

I am using documnet.body.scroll to disable the window scroll bar. This
works in IE only and not other browsers.

Can any one tell me if there is any such method which is cross browser
compatible.

Sam,

What you are doing is assuming the scroll bar belongs not only to the
particular document you display but also to the body part of that
document. However, given that any application *window* can choose to
display a scroll bar, it should be obvious that the thing you want to
really do is disable the feature in a window, not a document.

Yes, it is true that a document will set up a scroll bar in the window
(or within the web page for a <div> layer), but you appear to want to
disable the *window* feature - which is part of the underlying GUI of
the application. Naturally, the application can - and in many cases may
well - simply refuse to let you.

In this case though, a trip to www.w3c.org might help you find the
standard way to look at what you want to achieve. From your follow-ups,
it seems that you actually want to style a pop-up and that is certainly
possible. Remember though that many browsers may simply refuse to let
you have a pop-up, much less to style it in such an unfriendly way.
Jun 6 '06 #5

P: n/a

"sam" <za*****@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
Hi all,

I am using documnet.body.scroll to disable the window scroll bar. This
works in IE only and not other browsers.

Can any one tell me if there is any such method which is cross browser
compatible.

If you don't find a better way, this may have to be a job for ScrollFreeze.

Usage: ScrollFreeze.on() , ScrollFreeze.off()

<SCRIPT type='text/javascript'>

ScrollFreeze = /*2843293230303620532E4368616C6D657273*/
{
propFlag : true,
Ydisp : 0,
Xdisp : 0,

on : function()
{
if(this.getProp())
window.onscroll=function(){ ScrollFreeze.setXY(); }
},

off : function(){window.onscroll=null;},

getProp : function()
{
if( typeof window.pageYOffset != 'undefined' )
{
this.Ydisp=window.pageYOffset;
this.Xdisp=window.pageXOffset;
}
else
if(document.documentElement)
{
this.Ydisp=document.documentElement.scrollTop;
this.Xdisp=document.documentElement.scrollLeft;
}
else
if(document.body && typeof document.body.scrollTop != 'undefined')
{
this.Ydisp=document.body.scrollTop;
this.Xdisp=document.body.scrollLeft;
}
else
this.propFlag=false;

return this.propFlag;
},

setXY : function()
{
window.scrollTo( this.Xdisp, this.Ydisp );
}
}

</SCRIPT>
Jun 6 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.