Search code examples
scrollbarhta

Saving Scroll Position in HTA files


i have a HTA application with a wide scroll bar and i want to save the position of scroll bar that user left the application ,any solution?


Solution

  • Create a file named scroll.js in the same folder as your HTA file, which will be used for stocking the scrollbar's position. Then insert following code in your HTA:

    <script type="text/javascript">
         window.onbeforeunload = function(){
              var myfile = new ActiveXObject("Scripting.FileSystemObject").OpenTextFile("scroll.js",2,true);
              myfile.WriteLine("document.body.scrollLeft = '" + document.body.scrollLeft + "';");
              myfile.WriteLine("document.body.scrollTop = '" + document.body.scrollTop + "';");
              myfile.Close();
         }
    </script>
    

    So that when you open the HTA it puts the scrollbar like the user left it, you need to insert this code right before the </body> tag:

    <script type="text/javascript" src="scroll.js"></script>