From 4b339020b075d4b163906ecdaa3e45c09b409c42 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Sun, 24 Dec 2017 13:09:23 +0530 Subject: [PATCH 1/3] Snippet to detect device type --- snippets/detectDeviceType.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 snippets/detectDeviceType.md diff --git a/snippets/detectDeviceType.md b/snippets/detectDeviceType.md new file mode 100644 index 000000000..fcf4ea741 --- /dev/null +++ b/snippets/detectDeviceType.md @@ -0,0 +1,7 @@ +### detectDeviceType + +Detects weather the website is being opened in a mobile device or a desktop + +```js +const detectDevice = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? "Mobile" : "Desktop"; +``` \ No newline at end of file From 3af61ce755232290338823adff877eed34a2db6f Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Sun, 24 Dec 2017 13:10:31 +0530 Subject: [PATCH 2/3] Fixed typo and added examples --- snippets/detectDeviceType.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/snippets/detectDeviceType.md b/snippets/detectDeviceType.md index fcf4ea741..26123a32a 100644 --- a/snippets/detectDeviceType.md +++ b/snippets/detectDeviceType.md @@ -3,5 +3,8 @@ Detects weather the website is being opened in a mobile device or a desktop ```js -const detectDevice = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? "Mobile" : "Desktop"; +const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? "Mobile" : "Desktop"; + +detectDeviceType() -> "Mobile" +detectDeviceType() -> "Desktop" ``` \ No newline at end of file From 6ca563fcea9d7896fdbf81492510264fe8591e8b Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sun, 24 Dec 2017 13:49:11 +0200 Subject: [PATCH 3/3] Update detectDeviceType.md --- snippets/detectDeviceType.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/snippets/detectDeviceType.md b/snippets/detectDeviceType.md index 26123a32a..b2822a458 100644 --- a/snippets/detectDeviceType.md +++ b/snippets/detectDeviceType.md @@ -1,10 +1,11 @@ ### detectDeviceType -Detects weather the website is being opened in a mobile device or a desktop +Detects wether the website is being opened in a mobile device or a desktop/laptop. + +Use a regular expression to test the `navigator.userAgent` property to figure out if the device is a mobile device or a desktop/laptop. ```js const detectDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? "Mobile" : "Desktop"; - -detectDeviceType() -> "Mobile" -detectDeviceType() -> "Desktop" -``` \ No newline at end of file +// detectDeviceType() -> "Mobile" +// detectDeviceType() -> "Desktop" +```