Featured Categories
-
Lectora®
Lectora® is the most trusted authoring tool in the world. Rock out your creativity! Author courses any way you like. Lectora adheres to best practices for Accessibility and Web Content Accessibility Guidelines (WCAG), offers responsive authoring for eLearning, and publishes to any LMS (Learning Management System).
-
CenarioVR®
Experience virtual reality through CenarioVR®, our training and virtual reality (VR) authoring software that allows you to create immersive learning in minutes! No coding required!
-
Rockstar Learning Platform®
Our Rockstar Learning Platform® has all the features you’ll love. Help your employees be better at their jobs, more valuable to your company, and most effective in servicing your customers.
-
The Training Arcade®
Level up your learner engagement with the Training Arcade®! The Training Arcade is a library of fun, mobile-ready, casual games that can be rapidly customized with your content to create effective gaming!
-
ELB Learning Content
Did you know that our AssetLibrary™ has over 120 million engaging, interactive, and awe-inspiring templates and assets to help you become an eLearning Rockstar®?
JavaScript to detect user device in Lectora?

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.

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("Mobile");
}
else{
alert("not mobile");
}
};
Comments
-
You might find this useful: http://lectora.com/blog/browser-detection-lectora/0
-
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.0
-
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.:
VarMobileBrowser.set((is.iOS==1).toString());
The "is" object covers just about all browser features e.g:
is.ie, is.ie8, is.ie{etc}, is.firefox, is.safari, is.iOSSafari, is.awesomium, is.useHTML5Video, is.useHTML5Audio, ...
Take a look at the trivantis.js, function BrowserProps()
HTH
Regards, Peter
www.LectoraDeveloper.com0
Categories
- 35.9K All Categories
- 110 ✫ Announcements
- 33.2K Lectora®
- 31.1K Lectora Discussions
- 29K Lectora Desktop
- 2K Lectora Online
- 2K Lectora Feature Requests
- 71 Lectora User Groups
- 27 ELB Learning Content
- 27 ELB Learning Content Discussions
- 345 CenarioVR®
- 205 CenarioVR Discussions
- 140 CenarioVR Feature Requests
- 44 Rockstar Learning Platform®
- 41 Rockstar Learning Platform Discussions
- 108 CourseMill®
- 108 CourseMill Discussions
- 48 ReviewLink®
- 48 ReviewLink Discussions
- 7 The Training Arcade®
- 7 The Training Arcade Discussions
- 938 All Things eLearning
- 39 eLearning Development
- 546 Learning Management System (LMS) Integration
- 333 Web Accessibility
- 1.2K ♪ The Green Room
- 9 Additional Learning Products