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:

The videos Kurzgesagt channel creates are so beautifully animated, that I almost forget that I learn so much while watching them!

Might also interest you:

Hover to reveal Mask

Cloneable
Code
Design

A fixed background image that is revealed by mouse hover all over the section

Read more

Auto Change Tabs 2.0

Cloneable
Code
Interactions

A new and improved version for a Tabs element that automatically change tabs

Read more

Changing Text

Interactions
Cloneable
Tricks

Change text in a sentence/headline with Webflow's interactions

Read more