From 391b9cdcfe9aaa3a067a34fb1fa7129feb3493bf 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 99a1564b651006e32f8ef2571f829e18d9b6bc21 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 e0c5fb68b5444ac0939cd11a0f233e6c41062406 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" +```