android - Javascript doOnOrientationChange :can't fix a bug loading the page -


i used .js avoid landscape view mobile device. edited white full-screen image saying "this site not thought viewed in landscape mode, please turn device" shown each time rotate device portrait landscape. works except when load page , i'm in landscape mode. idea on how fix it? thanks

<script> (function() {     'use strict';      var ismobile = {         android: function() {             return navigator.useragent.match(/android/i);         },         blackberry: function() {             return navigator.useragent.match(/blackberry/i);         },         ios: function() {             return navigator.useragent.match(/iphone|ipad|ipod/i);         },         opera: function() {             return navigator.useragent.match(/opera mini/i);         },         windows: function() {             return navigator.useragent.match(/iemobile/i);         },         any: function() {             return (ismobile.android() || ismobile.blackberry() || ismobile.ios() || ismobile.opera() || ismobile.windows());         }     };     if (ismobile.any()) {         doonorientationchange();         window.addeventlistener('resize', doonorientationchange, 'false');     }      function doonorientationchange() {         var = document.getelementbyid('alert');         var b = document.body;         var w = b.offsetwidth;         var h = b.offsetheight;         (w / h > 1) ? (a.classname = 'show', b.classname = 'full-body') : (a.classname = 'hide', b.classname = '');     } })(); </script> 

update :

i tried adding window.orientation script wrong

if (orientation === "landscape-primary") {     doonorientationchange();     window.addeventlistener('resize',doonorientationchange,'false'); }  window.onload(doonorientationchange()); 

you need move doonorientationchange() function outside of other one, , call on pageload. should work:

<script> function checkmobile() {     var ismobile = false;     if (navigator.useragent.match(/android/i)      || navigator.useragent.match(/blackberry/i)      || navigator.useragent.match(/iphone|ipad|ipod/i)      || navigator.useragent.match(/opera mini/i)      || navigator.useragent.match(/iemobile/i)) {             ismobile = true;         }     return ismobile; } function doonorientationchange() {     var = document.getelementbyid('alert');     var b = document.body;     var w = b.offsetwidth;     var h = b.offsetheight;     if (checkmobile()) {         (w / h > 1) ? (a.classname = 'show', b.classname = 'full-body') : (a.classname = 'hide', b.classname = '');     } else {         a.classname = 'hide';         b.classname = '';     } } window.onload = doonorientationchange(); window.addeventlistener('resize', doonorientationchange, 'false'); </script> 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -