Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Callback Function From External Javascript
Wed, Aug 28 2013 6:31 AMPermanent Link

Chris Holland

SEC Solutions Ltd.

Avatar

Team Elevate Team Elevate

Is there anyway that I can pass a callback function into an external
Javascript file from EWB.

I am trying to access a geoLocation using something like the following code:

===============
EWB Code
===============

// not sure what to put in here as a parameter
external function GetPosition(???????);

function StartGetPosition()
{
// pass in the return function that I want called
  GetPosition(GetPositionSuccess);
}

function GetPositionSuccess(p)
{
// this function is called from external GetPosition() javascript
}


===========================
External Javascript File
===========================

function GetPosition(geoSuccess)
{
var options =
{
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};

if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(callbackSuccess,geoError,options);
}
}


--
Chris Holland
[Team Elevate]
Wed, Aug 28 2013 4:27 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Chris,

<< Is there anyway that I can pass a callback function into an external
Javascript file from EWB. >>

Yes, but it has to be a method of an object, not a generic function, and you
have to prototype the external call appropriately in order to avoid compiler
errors.

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Aug 28 2013 4:30 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Chris,

Some code might help. Smile

type

  TGetPositionSuccess = function (<Params>): <Return> of object;

external function GetPosition(PositionSuccess: TGetPositionSuccess);

Of course, if the function doesn't return a result, then you can just use a
procedure instead.

If you have any other questions, please let me know.

Tim Young
Elevate Software
www.elevatesoft.com
Image