Solved

JavaScript: legit use of setTimeout?

Posted on 2007-11-30
5
1,537 Views
Last Modified: 2013-11-19
Hi,

I've found this in the source code of http://iphone.facebook.com and have never seen it used as such. Would anyone be able to explain to me if this is a valid way of using setTimeout()?

<body onload="setTimeout(scrollTo, 0, 0, 1)">

I see three coordinates for window.scrollTo and a lack of a Timeout value. Is one being used implicitly?

Thanks.
0
Comment
Question by:stevefNYC
[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
  • 3
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
netsmithcentral earned 500 total points
ID: 20385743
This is a special FF only version of the window.setTimeout method.  Additional parameters passed after the first two are treated as parameters to the function call.

Mozilla (FF): http://developer.mozilla.org/en/docs/DOM:window.setTimeout
Microsoft (IE): http://msdn2.microsoft.com/en-us/library/ms536753.aspx
var functionName = function( param1, param2 ) {
     //Some function code
};
 
var timeoutPeriod = 0; //Time to wait
var functionParameter1 = 'someVal'; //A parameter to the function
var functionParameter2 = 'someVal'; //Another parameter
 
TimeoutID = setTimeout(functionName, timeoutPeriod, functionParameter1, functionParameter2);

Open in new window

0
 
LVL 3

Author Comment

by:stevefNYC
ID: 20385758
It can't be FF specific. This code is for a mobile safari application....
0
 
LVL 12

Expert Comment

by:netsmithcentral
ID: 20385762
It may have been adapted to work in other browsers, but according to that Mozilla developer doc (which I previously linked), it's designed for FF and doesn't work in other  browsers.
0
 
LVL 3

Author Comment

by:stevefNYC
ID: 20385773
Fair enough... I do see now that the first value is the timeout to wait and the second two are the coordinates. Just never seen it used this way.

Thank you!
0
 
LVL 12

Expert Comment

by:netsmithcentral
ID: 20385796
I hadn't seen it that way before today either.  Glad I could of assistance!
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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)

734 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