# How to Detect mobile device on hubl coding?

**URL:** <https://community.hubspot.com/t/how-to-detect-mobile-device-on-hubl-coding/26243>\
**Category:** CMS Development\
**Created:** [October 1, 2020, 9:28am UTC](https://community.hubspot.com/t/how-to-detect-mobile-device-on-hubl-coding/26243 "2020-10-01T09:28:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasadcolumbus](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/prasadcolumbus/32/69445_2.png) [@prasadcolumbus](https://community.hubspot.com/u/prasadcolumbus)\
**Post date:** [October 1, 2020, 9:28am UTC](https://community.hubspot.com/t/how-to-detect-mobile-device-on-hubl-coding/26243/1 "2020-10-01T09:28:32Z")

</div>

{{request.headers[‘user-agent’]}} this variable showing so much information.Can any one help me on this.

---

<div class="post-metadata">

**Author:** ![stefen](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/stefen/32/29274_2.png) [@stefen](https://community.hubspot.com/u/stefen)\
**Post date:** [October 1, 2020, 6:45pm UTC](https://community.hubspot.com/t/how-to-detect-mobile-device-on-hubl-coding/26243/2 "2020-10-01T18:45:20Z")

</div>

@prasadcolumbus I recommend either using [Smart Content](https://knowledge.hubspot.com/cos-general/get-started-with-smart-content) if you need to figure this out server side. Otherwise, you can do this client side fairly easily with either CSS media queries to show/hide specific things on mobile or desktop or use JS Match Media to change interaction of things on mobile/desktop.

---

<div class="post-metadata">

**Author:** ![Kevin-C](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kevin-c/32/34570_2.png) [@Kevin-C](https://community.hubspot.com/u/Kevin-C)\
**Post date:** [October 2, 2020, 3:29pm UTC](https://community.hubspot.com/t/how-to-detect-mobile-device-on-hubl-coding/26243/3 "2020-10-02T15:29:56Z")

</div>

Hey @prasadcolumbus

Thats expression really shouldn’t return a value that’s very large at all, ~120-150 characters with spaces.

Take a look at [this resource]([http://Mozilla/5.0%20](http://Mozilla/5.0%20)(Macintosh; Intel Mac OS X 10\_14\_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36) regarding the possible values it can return.

I wonder if you could do somehting like:

```lia-code-sample
{% set agent = request.headers['user-agent']|lower|split(" ") %}

{% set isMobile = agent.index("mobile") > -1 ? true : false %}

```

Obviously this will need more research as I’m not familiar enought with the user agents to know if it alwyas contains " mobile".

Thoughts?

---

<div class="post-metadata">

**Author:** ![prasadcolumbus](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/prasadcolumbus/32/69445_2.png) [@prasadcolumbus](https://community.hubspot.com/u/prasadcolumbus)\
**Post date:** [October 5, 2020, 7:29am UTC](https://community.hubspot.com/t/how-to-detect-mobile-device-on-hubl-coding/26243/4 "2020-10-05T07:29:16Z")

</div>

Thank you so much @Kevin-C it’s working

---

<div class="post-metadata">

**Author:** ![georgemarket8](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/georgemarket8/32/82448_2.png) [@georgemarket8](https://community.hubspot.com/u/georgemarket8)\
**Post date:** [January 25, 2021, 12:43pm UTC](https://community.hubspot.com/t/how-to-detect-mobile-device-on-hubl-coding/26243/5 "2021-01-25T12:43:57Z")

</div>

Hello Kevin,  
I am getting isMobile = true for Android but not on iOS phones. What do you think the issue is?  
Thank you in advance,  
George

---

<div class="post-metadata">

**Author:** ![georgemarket8](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/georgemarket8/32/82448_2.png) [@georgemarket8](https://community.hubspot.com/u/georgemarket8)\
**Post date:** [January 25, 2021, 4:02pm UTC](https://community.hubspot.com/t/how-to-detect-mobile-device-on-hubl-coding/26243/6 "2021-01-25T16:02:15Z")

</div>

Found it.  
The agent value is different from a mobile to another. So splitting it doesn’t work. Therefore I went for this solution below:  
{% set agent = request.headers[‘user-agent’]|lower|string %}  
{% set is\_mobile = false %}  
{% if agent is string\_containing “mobile” %}  
{% set is\_mobile = true %}  
{% endif %}  
Thank you.

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [January 26, 2021, 3:07pm UTC](https://community.hubspot.com/t/how-to-detect-mobile-device-on-hubl-coding/26243/7 "2021-01-26T15:07:19Z")

</div>

@georgemarket8 ,

thanks for adding your solution to the post 😀

---

<div class="post-metadata">

**Author:** ![georgemarket8](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/georgemarket8/32/82448_2.png) [@georgemarket8](https://community.hubspot.com/u/georgemarket8)\
**Post date:** [February 12, 2021, 12:44am UTC](https://community.hubspot.com/t/how-to-detect-mobile-device-on-hubl-coding/26243/8 "2021-02-12T00:44:54Z")

</div>

😁

---

<div class="post-metadata">

**Author:** ![linealves](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/linealves/32/38114_2.png) [@linealves](https://community.hubspot.com/u/linealves)\
**Post date:** [July 13, 2021, 6:17pm UTC](https://community.hubspot.com/t/how-to-detect-mobile-device-on-hubl-coding/26243/9 "2021-07-13T18:17:58Z")

</div>

Hey! where exactly I place this code? Should I add this to my forms? Sorry not a developer lol

---

<div class="post-metadata">

**Author:** ![georgemarket8](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/georgemarket8/32/82448_2.png) [@georgemarket8](https://community.hubspot.com/u/georgemarket8)\
**Post date:** [July 14, 2021, 6:00pm UTC](https://community.hubspot.com/t/how-to-detect-mobile-device-on-hubl-coding/26243/10 "2021-07-14T18:00:09Z")

</div>

Heyy!  
You can play with the below code in a custom module that you create:  
{% set agent = request.headers[‘user-agent’]|lower|string %}  
{% set is\_mobile = false %}

YOUR DESKTOP CONTENT GOES HERE…  
{% if agent is string\_containing “mobile” %}  
{% set is\_mobile = true %}

YOUR MOBILE CONTENT GOES HERE…  
{% endif %}
