DevByPowerPoint

Detect mobile device in Storyline

May 7th, 2024 (edited)
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. function isMobileDevice() {
  2. // Check for mobile-specific user agent keywords
  3. const mobileKeywords = ['Mobi', 'Android', 'iPhone', 'iPad', 'Windows Phone'];
  4. const userAgent = navigator.userAgent;
  5.  
  6. // Check if any mobile keywords exist in the user agent string
  7. return mobileKeywords.some(keyword => userAgent.includes(keyword));
  8. }
  9.  
  10. // Check if Storyline's player object is available
  11. if (window.hasOwnProperty('GetPlayer')) {
  12. // Get the Storyline player object
  13. const player = window.GetPlayer();
  14.  
  15. // Check if the course is being viewed on a mobile device
  16. const mobileView = isMobileDevice();
  17.  
  18. // Set the 'mobileView' variable in Storyline to indicate if it's a mobile device
  19. player.SetVar('mobileView', mobileView);
  20. }
  21.  
  22. /*Please ensure you have a True/False variable in Storyline named mobileView*/
Advertisement
Add Comment
Please, Sign In to add comment