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:

When your bath soap bar gets too small to use, don't throw it away! open the next bar, and when you finish showering, stick the small old bar to the back of the new bar. Onces they both dry, they will become one.

Might also interest you:

Thick Underline

Cloneable
Design
Tricks

An editable thick underline for your Headlines

Read more

ToDo List

Cloneable
Code

A todo list, created with JavaScript collected through the internet... ;)

Read more

Modal Lottie Transition

Cloneable
Design
Interactions

A full screen close/open animation with lottie

Read more