In updating to the old ('12) question, I think it can help many people!
I did not understand the true way to block the rotation of the device, but came up with the ideal alternative that I saw, and some people too.
Option A. One simple alert
Using a simple jQuery script, you can determine the orientation of your device.
if(window.innerHeight > window.innerWidth){ alert("Please use Landscape!"); }
Well, a simple alert is easy, but a notification might be nicer!
Option B. One great image
Just add a fixed element to the page that will be displayed when the orientation changes.
HTML
<div class="turnDeviceNotification"></div>
CSS
.turnDeviceNotification { position:fixed; top: 0; left:0; height:100%; width:100%; display: none; }
You can update this element with text, or simply connect it to the background image using
.turnDeviceNotification { background-image:url('../images/turnDevice.jpg'); background-size:cover; }
Just add a nice background to the image folder, for example below.
Noticed that the object has display: none ? This is because otherwise it will be shown even in portrait mode. Now all you have to do is use the script below, so the object is displayed only in landscape mode.
jQuery(window).bind('orientationchange', function(e) { switch ( window.orientation ) { case 0: $('.turnDeviceNotification').css('display', 'none'); // The device is in portrait mode now break; case 180: $('.turnDeviceNotification').css('display', 'none'); // The device is in portrait mode now break; case 90: // The device is in landscape now $('.turnDeviceNotification').css('display', 'block'); break; case -90: // The device is in landscape now $('.turnDeviceNotification').css('display', 'block'); break; } });
This will only show a notification if the orientation of the device has changed to landscape. 