Solved

javascript returns 'undefined'

Posted on 2009-07-03
4
367 Views
Last Modified: 2012-05-07
I have the following script which I want to capture the curret scroll position and write it to the screen. But instead of writing a figure it is writing the word 'undefined'

here is my script.

<script language=javascript>
var test = window.pageYOffset;
document.write(test);
</script>


0
Comment
Question by:Mr_Shaw
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
Kamaraj Subramanian earned 334 total points
Comment Utility
Hi,

please find the attached code

http://www.west-wind.com/WebLog/posts/4607.aspx

http://lists.evolt.org/archive/Week-of-Mon-20031117/151687.html
var ScrollTop = document.body.scrollTop;

if (ScrollTop == 0)

{

    if (window.pageYOffset)

        ScrollTop = window.pageYOffset;

    else

        ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
 

}

Open in new window

0
 
LVL 23

Assisted Solution

by:Kamaraj Subramanian
Kamaraj Subramanian earned 334 total points
Comment Utility

var xposition;

var yposition;

function saveScrollC() {

xposition = document.body.scrollLeft:window.pageXOffset;

 yposition = document.body.scrollTop:window.pageYOffset;

} 

Open in new window

0
 
LVL 9

Assisted Solution

by:Shahzad Fateh Ali
Shahzad Fateh Ali earned 166 total points
Comment Utility
Your code will only work in netscape.
Refer to following document for complete list

http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
0
 

Author Closing Comment

by:Mr_Shaw
Comment Utility
thanks
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now