Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts

    Auto Refresh - Stop Page Scrolling

    I'm attaching my php test file but this is a JS problem. When I scroll down in the web page and the meta refresh hits, in Windows Safari and IE6/7/8 browsers, the web page re-positions back to the top. In Opera and FF the page refreshes but it stays where it is.

    Can someone look at my test script and see why it is not working in IE and Win Safari? My goal is to have the web page not re-position to the top on the auto refresh.

    Thanks...
    Attached Files Attached Files
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    NJ, USA
    Posts
    476
    Thanks
    2
    Thanked 70 Times in 69 Posts
    It's actually just a matter of what each browser does. Firefox is nice in that it will reposition the scroll to where you last were, but IE just doesn't have that implemented. Try removing your script altogether and see if Firefox and Opera still reposition (they probably will).

    For your script to actually have a chance of working though, you need to wait for the entire document to load first before trying to set the scroll value. Right now, there is nothing on the document when you set the scroll values, so the browser is automatically setting them back to 0 (as it will not let you scroll to what is not there). You can try wrapping your "scroll reset" code in a window onload handler. Ex:
    Code:
    window.onload = function() {
      // set scroll values here.  
      // this function will run when the page has finished loading
    }
    Why do you need a meta refresh anyway by the way? Is the thing that gets updated something that can be updated via AJAX? Using AJAX would be a lot more reliable (and a lot less hacky) than setting cookies and attempting to re-scroll the document to the correct position. Not to mention, the user will see this refresh/scroll happen every so often when they could be in the middle of reading something, and that could be very annoying.

    If you're not sure of what you're trying to do can be done with AJAX, then post either your page, or a link to your page and I can let you know if it's possible or not.

    -Greg

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts
    Yes Opera and FF work without that code.

    I fear there is too much data and formatting, etc. for this to work with Ajax.

    The form fetches messaging records and displays them on the page - sort of like email so I want to refresh the page so it grabs the latest messages.

    Not sure what you mean by "...Right now, there is nothing on the document when you set the scroll values..."

    When I display that test page I can scroll down and wait for the refresh and in Opera and FF the page stays put. In IE and Win Safari it resets to the top.

    I'll try our window.onload() suggestion and see if I can make it work that way.

    Thanks
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #4
    Regular Coder
    Join Date
    Feb 2009
    Location
    NJ, USA
    Posts
    476
    Thanks
    2
    Thanked 70 Times in 69 Posts
    What I mean by "there is nothing in the document when you set the scroll values", I mean that the browser processes the page from the top to the bottom. So with your current code, the browser will create the start <html> tag, create the start <head> tag, and then start running your script. By the time the browser executes the line document.body.scrollTop = posy, the only two things in the document are the start <html> and start <head> tags (i.e. there is not yet even a <body> tag, or any of the content within it that would cause scroll bars to appear). Try doing alert( document.body.scrollTop ); right after you set it. I bet it will alert 0.

    By using a window onload handler, you wait until all html elements have been created on the page before running the code in that function. That might give your script a chance to set the correct scroll value.

    -Greg

  • #5
    Regular Coder
    Join Date
    Feb 2009
    Location
    NJ, USA
    Posts
    476
    Thanks
    2
    Thanked 70 Times in 69 Posts
    Hey, any luck on this?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •