Difference between revisions of "MediaWiki:Common.js"

From Utpalasia Wiki
Jump to navigation Jump to search
(removed detectmobilebrowser code (couldn't get regular page, even on desktop (had to disable JS)), switched to simplistic UA sniffing)
(change to user-agent string detection again)
 
(12 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
{
 
{
 
   var ua = navigator.userAgent;
 
   var ua = navigator.userAgent;
   if( navigator.userAgent.match(/Android/i)
+
 
  || navigator.userAgent.match(/webOS/i)
+
   if(ua.match(/Android/i))
  || navigator.userAgent.match(/iPhone/i)
+
  {
  || navigator.userAgent.match(/iPod/i)
+
    if(ua.match(/Mobile/i))
  || navigator.userAgent.match(/BlackBerry/i)
+
    {
  || navigator.userAgent.match(/Windows Phone/i))
+
      window.location.replace(document.URL + "?useformat=mobile");
 +
    }
 +
  }
 +
  else if((/webos|iphone|ipod|blackberry|windows phone|bada/i).test(ua))
 
   {
 
   {
 
     window.location.replace(document.URL + "?useformat=mobile");
 
     window.location.replace(document.URL + "?useformat=mobile");
 
   }
 
   }
 
}
 
}

Latest revision as of 19:04, 7 April 2013

/* Any JavaScript here will be loaded for all users on every page load. */

if(document.URL.search("mobile") == -1)
{
  var ua = navigator.userAgent;

  if(ua.match(/Android/i))
  {
    if(ua.match(/Mobile/i))
    {
      window.location.replace(document.URL + "?useformat=mobile");
    }
  }
  else if((/webos|iphone|ipod|blackberry|windows phone|bada/i).test(ua))
  {
    window.location.replace(document.URL + "?useformat=mobile");
  }
}