User:JFletcher/common.js: Difference between revisions
(Now detects if using a "complex URL" (such as a diff) so that it can add the correct suffix (?useformat=mobile vs &useformat=mobile)) |
(Oops, left in my test version) |
||
Line 1: | Line 1: | ||
// Automatically redirecting to mobile site if being accessed from iPhone | // Automatically redirecting to mobile site if being accessed from iPhone | ||
var mobile = navigator.userAgent.match(/ | var mobile = navigator.userAgent.match(/iPhone/i); | ||
var url = document.URL; | var url = document.URL; | ||
var mobileurl = url.match(/\useformat=mobile/); | var mobileurl = url.match(/\useformat=mobile/); | ||
var complexurl = url.match(/index. | var complexurl = url.match(/index.php/); | ||
var mobileurlsimple = url + "?useformat=mobile"; | var mobileurlsimple = url + "?useformat=mobile"; |
Revision as of 06:43, 7 April 2012
// Automatically redirecting to mobile site if being accessed from iPhone var mobile = navigator.userAgent.match(/iPhone/i); var url = document.URL; var mobileurl = url.match(/\useformat=mobile/); var complexurl = url.match(/index.php/); var mobileurlsimple = url + "?useformat=mobile"; var mobileurlcomplex = url + "&useformat=mobile"; if(mobile && !mobileurl) window.location = (complexurl)? mobileurlcomplex : mobileurlsimple;