?
Solved

scroll position javascript

Posted on 2008-11-11
2
Medium Priority
?
497 Views
Last Modified: 2012-05-11
i have some script which i was hoping will remember my scroll position and move my explorer window upon asp.net postback.

<script type="text/javascript">

function scrollToC() {
  window.scrollTo(xposition,yposition);
}

function saveScrollC() {
    var xposition;
    var yposition;

 xposition = document.body.scrollLeft:window.pageXOffset;
 yposition = document.body.scrollTop:window.pageYOffset;
}
</script>

<body onload="javascript:scrollToC()">

I am getting an object expected error. I don't usualy program in javascript so I am finding it hard to de-bug.

Also are the variables in one function see in another (i.e are they public variables)?
0
Comment
Question by:Mr_Shaw
  • 2
2 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 22938696
When do you call saveScrollToC and where are the cookie or hidden form field  that remembers the position across a reload
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 22938704
And yes, you need to define the vars outside the functions to access them from other functions

var xposition;
var yposition;
function saveScrollC() {
 xposition = document.body.scrollLeft:window.pageXOffset;
 yposition = document.body.scrollTop:window.pageYOffset;
}
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Moore’s Law has proven itself time and time again since it was first introduced. So what’s next? Will Moore’s law continue to remain relevant, or will new technology take over and bring us the next big advancement in computing?
Loops Section Overview
Screencast - Getting to Know the Pipeline
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question