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)
(added some OSs)
Line 4: Line 4:
 
{
 
{
 
   var ua = navigator.userAgent;
 
   var ua = navigator.userAgent;
   if( navigator.userAgent.match(/Android/i)
+
   if( ua.match(/Android/i)
   || navigator.userAgent.match(/webOS/i)
+
   || ua.match(/webOS/i)
   || navigator.userAgent.match(/iPhone/i)
+
   || ua.match(/iPhone/i)
   || navigator.userAgent.match(/iPod/i)
+
   || ua.match(/iPod/i)
   || navigator.userAgent.match(/BlackBerry/i)
+
   || ua.match(/BlackBerry/i)
   || navigator.userAgent.match(/Windows Phone/i))
+
   || ua.match(/Windows Phone/i)
 +
  || ua.match(/Bada/i)
 +
  || ua.match(/Symbian/i))
 
   {
 
   {
 
     window.location.replace(document.URL + "?useformat=mobile");
 
     window.location.replace(document.URL + "?useformat=mobile");
 
   }
 
   }
 
}
 
}

Revision as of 19:32, 6 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)
   || ua.match(/webOS/i)
   || ua.match(/iPhone/i)
   || ua.match(/iPod/i)
   || ua.match(/BlackBerry/i)
   || ua.match(/Windows Phone/i)
   || ua.match(/Bada/i)
   || ua.match(/Symbian/i))
  {
    window.location.replace(document.URL + "?useformat=mobile");
  }
}