修复Android屏幕旋转

时间:2013-12-06 15:04:41

标签: javascript android ios mobile rotation

我有一个网站,我需要根据用户观看网站的方式显示不同的网页。如果它在桌面上,它们会看到一个页面,如果它在移动纵向上,它们将看到一个不同的页面,如果它在移动环境中,同样的东西,则加载另一个不同的页面。

所以我添加了这个javascript代码,起初在Android中工作得很好,但现在只适用于iphone或ipads,但不适用于Android设备。你能告诉我它有什么问题吗?

非常感谢!

纳乔。

    var redirectOrientation = function(){
    var uagent = navigator.userAgent.toLowerCase();
if (uagent.search("android") > -1) {

    if (window.orientation == 90 || window.orientation == 270 )  {
      if (window.location.href.indexOf("landscape")<0){
window.location.href="http://www.creo.com.uy/web/mytho/inicio-landscape/";
    }
    }
    if (window.orientation == 0 || window.orientation == 180 )  {
      if (window.location.href.indexOf("mobile")<0){
       window.location.href="http://www.creo.com.uy/web/mytho/";
    }


        }

else {

    if (window.orientation == -90 || window.orientation == 90 )  {
      if (window.location.href.indexOf("landscape")<0){
       window.location.href="http://www.creo.com.uy/web/mytho/inicio-landscape/";
    }
    }
    if (window.orientation == 0 || window.orientation == 180 )  {
      if (window.location.href.indexOf("mobile")<0){
       window.location.href="http://www.creo.com.uy/web/mytho/";
    }
    }
    }
}
    window.addEventListener('orientationchange',redirectOrientation);
    window.addEventListener('onorientationchange',redirectOrientation);


    redirectOrientation();

0 个答案:

没有答案