Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1555
  • Last Modified:

JavaScript: legit use of setTimeout?

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
stevefNYC
Asked:
stevefNYC
  • 3
  • 2
1 Solution
 
netsmithcentralCommented:
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
 
stevefNYCAuthor Commented:
It can't be FF specific. This code is for a mobile safari application....
0
 
netsmithcentralCommented:
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
 
stevefNYCAuthor Commented:
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
 
netsmithcentralCommented:
I hadn't seen it that way before today either.  Glad I could of assistance!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now