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");




  • ssneg
    ssneg Community Member Posts: 1,456 ♪ Opening Act ♪
  • digitalartist
    digitalartist Community Member Posts: 2
    You know, I tried that one before and it didn't work. Now I went through all the steps again to make sure it was exactly the same as the tutorial, and it works!!! Thanks very much.
  • pjackson2462
    pjackson2462 Community Member Posts: 75 ♪ Opening Act ♪
    G'day Sergay,

    I know that this is old, but I'm a newbie here, you could use the already available global object "is" e.g.:


    The "is" object covers just about all browser features e.g:, is.ie8,{etc}, is.firefox, is.safari, is.iOSSafari, is.awesomium, is.useHTML5Video, is.useHTML5Audio, ...

    Take a look at the trivantis.js, function BrowserProps()


    Regards, Peter