Everything in the code !!!!
[Html]
<! DOCTYPE html>
<Head>
<Title> Acceleration Example </title>
<Script type = "text/javascript" charset = "UTF-8" src = "cordova. js"> </script>
<Script type = "text/javascript" charset = "UTF-8">
Var watchID = null;
Document. addEventListener ("deviceready", onDeviceReady, false );
Function onDeviceReady ()
{
StartWatch ();
}
Function startWatch ()
{
Var options = {frequency: 3000 };
WatchID = navigator. accelerometer. watchAcceleration (onSuccess, onError, options );
}
Function stopWatch ()
{
If (watchID)
{
Navigator. accelerometer. clearWatch (watchID );
WatchID = null;
}
}
Function onSuccess (acceleration)
{
Var element = document. getElementById ('accesser ');
Element. innerHTML = 'acceleration X: '+ Acceleration. x +' <br/> '+
'Acceleration Y: '+ Acceleration. y +' <br/> '+
'Acceleration Z: '+ Acceleration. z +' <br/> '+
'Timestamp: '+ acceleration. Timestamp +' <br/> ';
}
Function onError ()
{
Alert ('oooops! ');
}
</Script>
</Head>
<Body>
<Div id = "accelerometer"> Waiting for accelerometer... </div>
<Button onClick = "stopWatch ();"> Stop Watching </button>
</Body>
</Html>
<! DOCTYPE html>
<Head>
<Title> Acceleration Example </title>
<Script type = "text/javascript" charset = "UTF-8" src = "cordova. js"> </script>
<Script type = "text/javascript" charset = "UTF-8">
Var watchID = null;
Document. addEventListener ("deviceready", onDeviceReady, false );
Function onDeviceReady ()
{
StartWatch ();
}
Function startWatch ()
{
Var options = {frequency: 3000 };
WatchID = navigator. accelerometer. watchAcceleration (onSuccess, onError, options );
}
Function stopWatch ()
{
If (watchID)
{
Navigator. accelerometer. clearWatch (watchID );
WatchID = null;
}
}
Function onSuccess (acceleration)
{
Var element = document. getElementById ('accesser ');
Element. innerHTML = 'acceleration X: '+ Acceleration. x +' <br/> '+
'Acceleration Y: '+ Acceleration. y +' <br/> '+
'Acceleration Z: '+ Acceleration. z +' <br/> '+
'Timestamp: '+ acceleration. Timestamp +' <br/> ';
}
Function onError ()
{
Alert ('oooops! ');
}
</Script>
</Head>
<Body>
<Div id = "accelerometer"> Waiting for accelerometer... </div>
<Button onClick = "stopWatch ();"> Stop Watching </button>
</Body>
</Html>