matchMedia()
MethodYou can simply use the JavaScript window.matchMedia()
method to detect a mobile device based on the CSS media query. This is the best and most reliable way to detected mobile devices.
The following example will show you how this method actually works:
<script>
$(document).ready(function(){
if(window.matchMedia("(max-width: 767px)").matches){
// The viewport is less than 768 pixels wide
alert("This is a mobile device.");
} else{
// The viewport is at least 768 pixels wide
alert("This is a tablet or desktop.");
}
});
</script>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Add Routing in Angular 10 App Tutorial
This is a step by step PHP 7 & MySQL...How to check if an element is hidden using jQuery
Use the jQuery :hidden Selector The j...How to Setup 404 Page in Angular 12
In this article, we will create 404 erro...Angular 12 Owl Carousel Tutorial Example
I will expound step by step tutorial ang...Laravel Collection count and countBy Method Example
In this article, we will discuss about h...