Maintain scroll position on post back script not work in IE?

Discussion in 'JavaScript' started by deny, May 28, 2009.

  1. #1
    Below is script that works perfectly in FF, Opera but not in IE
    -----------------------------------------
    Head section:

    <script type="text/javascript">
    function saveScrollPositions(theForm) {
    if(theForm) {
    var scrolly = typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement.scrollTop;
    var scrollx = typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement.scrollLeft;
    theForm.scrollx.value = scrollx;
    theForm.scrolly.value = scrolly;
    }
    }
    </script>


    In form:

    <form action="whatever.php" name="enrollment" method="post" onsubmit="return saveScrollPositions(this);">
    <input type="hidden" name="scrollx" id="scrollx" value="0" />
    <input type="hidden" name="scrolly" id="scrolly" value="0" />


    Just above </body>:

    <?php
    $scrollx = 0;
    $scrolly = 0;
    if(!empty($_REQUEST['scrollx'])) {
    $scrollx = $_REQUEST['scrollx'];
    }
    if(!empty($_REQUEST['scrolly'])) {
    $scrolly = $_REQUEST['scrolly'];
    }
    ?>

    <script type="text/javascript">
    window.scrollTo(<?php echo "$scrollx" ?>, <?php echo "$scrolly" ?>);
    </script>


    ----------------

    By testing with IE window.scrollTo does not remember position and always show window.scrollTo(0, 0); while FF correct remember position and scroll to right position.

    So anybody have idea what is wrong with IE?

    Thanks
     
    deny, May 28, 2009 IP