iphone orientation

Discussion in 'Public Game Developers Forum' started by sudhakararaog, Nov 15, 2010.

  1. sudhakararaog

    sudhakararaog Member

    Nov 15, 2010
    5
    0
    0
    i am using the following code i need to detect the chnage in orientation and in css i am simply chaging the background colors when in portrait and landscape mode however this code is not detecting the orientation change

    1.

    <head>
    <link rel="StyleSheet" href="iphone.css" type="text/css" media="screen" id="orient_css" />

    <script type="text/javascript">
    function orient()
    {
    switch(window.orientation)
    {
    case 0: document.getElementById("orient_css").href = "iphone_portrait.css";
    break;

    case -90: document.getElementById("orient_css").href = "iphone_landscape.css";
    break;

    case 90: document.getElementById("orient_css").href = "iphone_landscape.css";
    break;
    }
    }
    window.onload = orient();

    </script>
    </head>

    <body onorientationchange="orient();">



    2.
    <head>
    <script type="text/javascript">

    window.onload = function initialLoad() {
    updateOrientation();
    }

    function updateOrientation(){
    var contentType = "show_";
    switch(window.orientation){
    case 0:
    contentType += "normal";
    break;

    case -90:
    contentType += "right";
    break;

    case 90:
    contentType += "left";
    break;

    case 180:
    contentType += "flipped";
    break;
    }
    document.getElementById("page_wrapper").setAttribute("class", contentType);
    }

    </script>
    </head>


    please advice how to change the code to detect the iphone orientation

    thanks
     
  2. madmud101

    madmud101 Well-Known Member

    Dec 30, 2009
    1,068
    0
    0
    This is why i don't do coding. ;)
     

Share This Page