Back to all Elements

OS Detection with JavaScript

Short JavaScript code that detects which OS system the user is running and display div accordingly.

In short, what I did here is used the navigator.userAgent request header to detect what OS the user is running. This method is widely supported by browsers and not to hard to implement.

Once I know which OS, I show and hide divs in the project accordingly.

Here is the code:

<script>

if ( /iPhone|iPad|iPod/i.test(navigator.userAgent) ) {

 $("#android").hide();

 $("#web").hide();

}

else if ( /Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {

 $("#ios").hide();

 $("#web").hide();

}

else {

   $("#ios").hide();

   $("#android").hide();

}

</script>

Copy

Preview:

A tongue scraper is is so much better in cleaning your tongue instead of the normal brushing it.

Might also interest you:

Tabs with scrollable (sideways) Menu

Cloneable
Code
Design

A Webflow Tabs widget with some edits and custom code to make the menu scrollable on desktop & mobile

Read more

Contact form as a Chat widget

Cloneable
Code
Tricks

A contact form disguised as a chat widget.

Read more

Thick Underline

Cloneable
Design
Tricks

An editable thick underline for your Headlines

Read more