Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
62
rated 0 times [  69] [ 7]  / answers: 1 / hits: 29228  / 13 Years ago, mon, august 8, 2011, 12:00:00

I have a javascript code to redirect mobile phone users. Could you check the code, I've picked it up from the net, total newb and I'd value your input regarding the quality of the script...



Does it cover all types of mobile phones?



function RedirectSmartphone(url) {
if (url && url.length > 0 && IsSmartphone())
window.location = url;
}

function IsSmartphone() {
if (DetectUagent(android)) return true;
else if (DetectUagent(iphone)) return true;
else if (DetectUagent(ipod)) return true;
else if (DetectUagent(symbian)) return true;
return false;
}

function DetectUagent(name) {
var uagent = navigator.userAgent.toLowerCase();
if (uagent.search(name) > -1)
return true;
else
return false;
}
RedirectSmartphone(http://mobile.version.com);

More From » jquery

 Answers
85

Depending what you mean by all the phones, but it doesn't cover, for example, blackberry phones, or tablets.



A better approach would be to detect the screen resolution, e.g. in jQuery you could do:



if ( (screen.width < 1024) && (screen.height < 768) ) { 
window.location = 'http://mobile.site.com';
}

[#90742] Sunday, August 7, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nolancampbellc

Total Points: 9
Total Questions: 102
Total Answers: 101

Location: Saint Vincent and the Grenadines
Member since Mon, Jan 16, 2023
1 Year ago
;