Forum Discussion
karenforkish
8 years agoCommunity Member
Is there a way to know what device is being used to view a course?
Now that we have this lovely responsive player in Storyline 360, is there a way to to find out what device is being used to view a course so that we can set a variable and adjust some internal contr...
numanjohn
4 years agoCommunity Member
There is a JavaScript API built-in for detecting media. The JavaScript window.matchMedia() method returns a MediaQueryList object representing the results of the specified CSS media query string. You can use this method to detect mobile device based on the CSS media query.
<script>
$(document).ready(function(){
let isMobileDevice = window.matchMedia("only screen and (max-width: 760px)").matches;
if(isMobileDevice){
// The viewport is less than 768 pixels wide
//Conditional script here
} else{
//The viewport is greater than 700 pixels wide
alert("This is not a mobile device.");
}
});
</script>
You can use above script to do show/hide elements depending on the screen size.