Solved

JavaScript: legit use of setTimeout?

Posted on 2007-11-30
5
1,526 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
  • 3
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
netsmithcentral earned 500 total points
Comment Utility
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
Comment Utility
It can't be FF specific. This code is for a mobile safari application....
0
 
LVL 12

Expert Comment

by:netsmithcentral
Comment Utility
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
Comment Utility
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
Comment Utility
I hadn't seen it that way before today either.  Glad I could of assistance!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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