Skip to content Skip to sidebar Skip to footer

Working With Orientation Of The IPad In Javascript

I am working with the orientation in iPad . I am using phone gap for building the application. I have done following code for orientation change : function updateOrientatio

Solution 1:

Both Safari and Android support a simple orientation change event listener.

<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>PhoneGap</title>
     <script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script>
     <script type="text/javascript" charset="utf-8" src="main.js"></script>

</head>
<body onload="init();" >

    <h2>Orientation Test</h2>
    <div id="status"></div>

</body>
</html>

And js code :

function init() {
    window.addEventListener("orientationchange", orientationChange, true);
}

function orientationChange(e) {
    var orientation="portrait";
    if(window.orientation == -90 || window.orientation == 90) orientation = "landscape";
        document.getElementById("status").innerHTML+=orientation+"<br>";
}

Source


Post a Comment for "Working With Orientation Of The IPad In Javascript"