document.body.scroll does not work in Firefox

Discussion in 'Javascript' started by sam, Jun 5, 2006.

  1. sam

    sam Guest

    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
     
    sam, Jun 5, 2006
    #1
    1. Advertising

  2. sam

    Randy Webb Guest

    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/
     
    Randy Webb, Jun 6, 2006
    #2
    1. Advertising

  3. sam

    sam Guest

    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/
     
    sam, Jun 6, 2006
    #3
  4. sam

    Randy Webb Guest

    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/
     
    Randy Webb, Jun 6, 2006
    #4
  5. sam

    The Magpie Guest

    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.
     
    The Magpie, Jun 6, 2006
    #5
  6. "sam" <> wrote in message
    news:...
    > 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>
     
    Stephen Chalmers, Jun 6, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Ui5OaWprYW1w?=

    Listbox disabled - cant scroll in IE - can scroll in Firefox

    =?Utf-8?B?Ui5OaWprYW1w?=, Nov 22, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,261
    =?Utf-8?B?Ui5OaWprYW1w?=
    Nov 22, 2006
  2. London Boy
    Replies:
    2
    Views:
    350
    Keith Bowes
    Jan 12, 2004
  3. Replies:
    0
    Views:
    191
  4. Klaus Jensen
    Replies:
    2
    Views:
    177
    David Dorward
    Aug 21, 2007
  5. Martin Rinehart

    document or document.body

    Martin Rinehart, Dec 6, 2008, in forum: Javascript
    Replies:
    13
    Views:
    185
    Martin Honnen
    Dec 7, 2008
Loading...

Share This Page