Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

javascript returns 'undefined'

Posted on 2009-07-03
4
Medium Priority
?
379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
Kamaraj Subramanian earned 1336 total points
ID: 24772371
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 1336 total points
ID: 24772373

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 664 total points
ID: 24772390
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
ID: 31599565
thanks
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

604 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