★ TouchArcade needs your help. Click here to support us on Patreon.

iphone orientation

11-15-2010, 06:11 PM
#1
Joined: Nov 2010
Posts: 5
iphone orientation

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").setAttribu te("class", contentType);
}

</script>
</head>


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

thanks
11-16-2010, 01:47 AM
#2
Joined: Dec 2009
Posts: 1,068
This is why i don't do coding.

www.oneclickmac.com - News, Reviews and Discussion on Mac App Store Gaming.

Latest Reviews:
RAGE Mafia II Doodle Fit