Detect Whether the Browser Is on a Mobile Device
# Detect Whether the Browser Is on a Mobile Device
const flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i);
if(flag){
// Mobile device
} else {
// Desktop
}
1
2
3
4
5
6
2
3
4
5
6
Edit (opens new window)
Last Updated: 2026/03/21, 12:14:36