Si vous n'êtes pas familier avec phonegap, consultez Jonathan Stark's great introduction.
Si vous êtes déjà familier avec phonegap et avez juste besoin d'un extrait de code, alors jetez un oeil au rapport de bug here. Comme vous pouvez le voir, il semble qu'il y ait quelques problèmes avec watchOrientation dans la version actuelle, mais Shazron fournit une solution de contournement que j'ai copiée ici:
function onDeviceReady()
{
// do your thing!
document.addEventListener("orientationChanged", UpdateOrientation);
}
function UpdateOrientation(e)
{
switch(e.orientation)
{
case 0: // portrait
case 180: // portrait
// do your thing here
break;
case -90: // landscape
case 90: // landscape
// do your thing here
break;
}
}