473,785 Members | 2,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Orientation change setection only works from Portrait to Landscape

7 New Member
I need to detect mobile browser screen orientation change. It's interesting that the following javascript can detect the orientation change from portrait to landscape but not the opposite. Why?

Expand|Select|Wrap|Line Numbers
  1. <script type='text/javascript'>
  2.     detectOrientation();
  3.     window.onorientationchange = detectOrientation;
  4.     function detectOrientation() {
  5.         var panel2CleinetID = '<%= Panel2.ClientID %>';
  6.         var panel2 = document.getElementById(panel2CleinetID);
  7.         var panel3CleinetID = '<%= Panel3.ClientID %>';
  8.         var panel3 = document.getElementById(panel3CleinetID);
  9.  
  10.         //if (typeof window.onorientationchange != 'undefined') {
  11.         if (window.orientation) {
  12.             if (orientation == 0) {
  13.                 //Do Something In Portrait Mode
  14.                 if (panel2) {
  15.                     panel2.style.display = 'inherit';
  16.                 }
  17.                 if (Panel3) {
  18.                     panel3.style.display = 'none';
  19.                 }
  20.                 //alert('orientation == 0');
  21.             }
  22.             else if (orientation == 90) {
  23.                 //Do Something In Landscape Mode
  24.                 if (panel2) {
  25.                     panel2.style.display = 'none';
  26.                 }
  27.                 if (Panel3) {
  28.                     panel3.style.display = 'inherit';
  29.                 }
  30.                 //alert('orientation == 90');
  31.             }
  32.             else if (orientation == -90) {
  33.                 //Do Something In Landscape Mode
  34.                 if (panel2) {
  35.                     panel2.style.display = 'none';
  36.                 }
  37.                 if (Panel3) {
  38.                     panel3.style.display = 'inherit';
  39.                 }
  40.                 //alert('orientation == -90');
  41.             }
  42.             else if (orientation == 180) {
  43.                 //Do Something In Portrait Mode
  44.                 if (panel2) {
  45.                     panel2.style.display = 'inherit';
  46.                 }
  47.                 if (Panel3) {
  48.                     panel3.style.display = 'none';
  49.                 }
  50.                 //alert('orientation == 180');
  51.             }
  52.             else {
  53.                 // Get the screen size and determine if it is in portrait
  54.                 // or landscape mode by comparing the width and height.
  55.                 var wid = screen.width;
  56.                 var ht = screen.height;
  57.                 if (wid > ht) {
  58.                     if (panel2) {
  59.                         panel2.style.display = 'none';
  60.                     }
  61.                     if (Panel3) {
  62.                         panel3.style.display = 'inherit';
  63.                     }
  64.                     //alert('wid > ht');
  65.                 }
  66.                 else {
  67.                     if (panel2) {
  68.                         panel2.style.display = 'inherit';
  69.                     }
  70.                     if (Panel3) {
  71.                         panel3.style.display = 'none';
  72.                     }
  73.                     //alert('wid < ht');
  74.                 }
  75.             }
  76.         }
  77.     }
  78. </script> 
Sep 7 '13 #1
0 1319

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3318
by: bettina | last post by:
My multilanguage website still doesn't work.... really it works after a refresh: when I first start the browser, I get the following error: Warning: main(lang..inc.php) : failed to open stream: No such file or directory in C:\wampp2\htdocs\set_language.php on line 6 Fatal error: main() : Failed opening required 'lang..inc.php' (include_path='\wampp2\php\pear\') in C:\wampp2\htdocs\set_language.php on line 6
5
9454
by: Robert Schuldenfrei | last post by:
Hi Again, Forgive me for posting this again, but old items seem to get little review. I thought I could adjust the viewer properties without any further aid from the NG, but I was wrong. When I print my reports to a file or directly to the printer, the orientation is landscape. This was set in the report itself using Designer | Printer Setup and setting the printer to landscape. When I send the report to the viewer, using the...
9
9908
by: Sean McKaharay | last post by:
Since no one can answer the following question: I have a issue. I need to create a command line application/or windows application that will take 2 parameters and will print to the default printer without any popups. the first parameter is the html file name(location) second is a switch that will tell the app to print in landscape or protrait. Basicly I when I type in (for example) PrintApp "c:\printthis.html" \L it should print the file...
0
964
by: wackyphill | last post by:
Anyone know why changing column properties in a DataGridView works ina form_Load() but not at the end of the form's constructor?
0
1337
by: Alpha | last post by:
How can I pint in Landscape when I use graphics.drawstring? Currently, I have to change my printer to Landscape to make it do so. The output is preview in a Crystal Report form that is setup as landscape but it still shows up as portrait. I skipped the preview and sent it directly to the printer and it still is Portrait orientation. Thanks, Alpha
3
3895
by: PebblePicker | last post by:
hi all, is it possible to change print format to landscape using javascript/css or anything else which is suppoted in MOZILLA ? I could not find it anywhere.
0
1276
by: matvin | last post by:
When generating .NET Crystal Reports with Page Orientation as Landscape, a Blank page gets generated along with the report. But this is not the case when the page orientation is set with Portrait.Any help on this?
2
1192
by: MSCTC | last post by:
Hi Guys, This should be quite simple but my brains are being seriously racked. I have created a data access page as the report I want to generate is 4 pages (too long for a regular report). Access page looks good and works well with my query. The problem is, it will only print off in landscape regardless of how many times I change it to portrait. I have edited it both in Access and Frontpage by editing the actual html document. I have...
1
3029
by: muddasirmunir | last post by:
i am using vb6 i am facing one problem is datareport that in my computer i had instaled a panasonic printer and the data report show fine but when i take my project to my office computer in which another printer is installed (its HP) NOW, in many reports when we run data reprot its give errror "report widht is larger than papper widht"
4
6813
by: J360 | last post by:
Access 2003. I've set the report orientation to landscape using VB. The report that pops up is in Portrait view, but page orientation is correctly set to Landscape and it prints in landscape orientation. The really odd thing is that if I step through the code using F8, it will open in PrintPreview Mode as Landscape. The relevant code is as follows. rpt.Section(acDetail).Visible = False With rpt .Printer.Orientation =...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10152
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.