They depend upon the User-Agent
of the browser to determine which kind of device the client is using.
Of course, User-Agents can be spoofed, and there isn't much that you can do to prevent it.
While there have been attempts to detect the real browser types by trying to invoke features that are specific to those browsers, this isn't reliable.
You can read more about User-Agent
here.