JavaScript to detect user device in Lectora?

digitalartist Community Member Posts: 2

I’ve been trying to get this to work and I can’t figure it out or find the info I need on the forums. I’m trying to add JavaScript to a Lectora title that detects what device a user is using. Any help is appreciated. :) I did the following:

1. Created a variable in Lectora called MobileDevice

2. Added an action to each page to use that variable

3. Added an external HTML object with the code listed below. I’ve tried using every type and none work right. Using Header Scripting or Top of File messes up the page layout.

4. Added an action below that to run the JS (function:isMobile())

5. Added another action telling Lectora to choose a page based on whether the variable I created has the value “true”

This is my code: (the alerts are just to show me it's working)

function isMobile() = {

Android: function() {

return navigator.userAgent.match(/Android/i);


BlackBerry: function() {

return navigator.userAgent.match(/BlackBerry/i);


iOS: function() {

return navigator.userAgent.match(/iPhone|iPad|iPod/i);


Opera: function() {

return navigator.userAgent.match(/Opera Mini/i);


Windows: function() {

return navigator.userAgent.match(/IEMobile/i);


any: function() {

return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());


if(isMobile.any() ){

VarMobileDevice = "true";




alert("not mobile");