Skip to content

Commit 2424cf0

Browse files
committed
Improve mobile detection
1 parent 8dbf2fc commit 2424cf0

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/mixins/IsMobile.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
https://www.ditdot.hr/en
55
*/
66

7-
// Simple mobile device/tablet detection
8-
const isIos = navigator.userAgent.match(/iphone|ipad|ipod/i) || (navigator.userAgent.indexOf("Mac") !== -1 && "ontouchend" in document)
9-
const isMobile = !!(typeof navigator !== 'undefined' && (isIos || navigator.userAgent.match(/android/i)))
7+
let
8+
isIos = false,
9+
isMobile = false
1010

11-
// Mixin that adds an `isMobile` data variable
11+
if (typeof navigator !== 'undefined' && typeof document !== 'undefined') {
12+
// Simple mobile device/tablet detection
13+
isIos = navigator.userAgent.match(/iphone|ipad|ipod/i) || (navigator.userAgent.indexOf('Mac') !== -1 && 'ontouchend' in document)
14+
isMobile = isIos || navigator.userAgent.match(/android/i)
15+
}
16+
17+
// Mixin that adds `isMobile` and `isIos` data variables
1218
export const IsMobile = {
1319
data() {
1420
return {

0 commit comments

Comments
 (0)