White Arrow icon
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:

Share:

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:

Round Scroll Indicator / Progress Bar

Cloneable
Interactions
Animation

A round scroll indicator mad with Webflow elements and interactions

Read more
White Arrow icon

Pass Parameters

Cloneable
Code

Pass input fields parameters and add them to the destination URL.

Read more
White Arrow icon

Before / After effect

Cloneable
Tricks
Interactions

A Before / After effect for photos, without any code. Only Webflow's interaction.

Read more
White Arrow icon