JS - mobile and url

Please help me in writing the code if the user comes from mobile and URL contains .html

[code] if (navigator.userAgent.match(/ Android /)) {
if (navigator.userAgent.match(/ Mobile /)) {
user = “Android”;
}
if ((user == “Android”) {
alert(“Andriod”);
}

[code]

userAgent can be anything (I have all of mine set to the same value regardless of the browser or device) - the best you can do for detecting mobile devices is to check the viewport size.

I’d even say that unless you are doing this for gathering some kind of rough statistical data the pursuit is pointless.

That is, if you are thinking of this as a way of “device sniffing” to serve different mark-up or style or script etc. based on device, you’re approaching this the wrong way. Trying to keep up with all devices would be almost as difficult as counting the grains of sand on a beach.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.