Detecting iPad Orientation in Safari using JavaScript

I stumbled on that by accident. One of my javascript-variables was called orientation and was not correctly used on the iPad’s Safari.

After looking at its content, I found out that you can detect the device orientation. I knew you can handle many cool things on the iOS, like swipes in javascript, but this one was new to me.

So, what are you going to do with this? It’s obvious: Style your website or re-order your content to match exactly your iPad’s orientation ;-)

You can use javascript in an event handler, loop, or whatever by accessing window.orientation (or only orientation).

Here’s an example on how to detect the current orientation of the iPad device either by pressing a button or when the orientation changes, using an event called onOrientationChange:





You can also use CSS Stylesheets using the media definition:




The detection is not restricted to the iPad, it should work on all iOS devices.

Time-based Kill-Switch for iOS Apps

If you want to set your App to stop working at a specific date, you are thinking about a time-based Kill-Switch.

You will want to do something like that if you worry about illegal copies of your Apps, you have sent out for testing purpose.

Realizing such switch is very easy, here’s an example:

	NSDate *killDate = [NSDate dateWithTimeIntervalSinceNow:0];
	int killDateTs = [killDate timeIntervalSince1970];
	if ( killDateTs > 1280624461 ) { // 2010-08-01
		exit(0);
	}


Replace the timestamp with your own expire time and your App will stop working at that day.

Switch to our mobile site