Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Store screen resolution

  • Soparnlin_47063
  • Soparnlin_47063's Avatar Topic Author
  • Offline
  • Banned
  • Banned
More
8 years 8 months ago #122229 by Soparnlin_47063
Store screen resolution was created by Soparnlin_47063
Hi,
I'd like to know if it's possible to store the screen resolution of each participant ?
I need to know if people are watching the survey on their tablet or desktop.

Thanks!
D.
The topic has been locked.
More
8 years 8 months ago - 8 years 8 months ago #122242 by Ben_V
Replied by Ben_V on topic Store screen resolution
Hi,
Adapt this code collecting all the browser information in a short-text question
Code:
<script type="text/javascript">
    var SID = '{SID}';
    var GID = '{GID}';
    var QID = '{QID}';
 
    var nVer = navigator.appVersion;
    var nAgt = navigator.userAgent;
    var browserName = navigator.appName;
    var fullVersion = '' + parseFloat(navigator.appVersion);
    var majorVersion = parseInt(navigator.appVersion, 10);
    var nameOffset, verOffset, ix;
 
    // In Opera, the true version is after "Opera" or after "Version"
    if ((verOffset = nAgt.indexOf("Opera")) != -1) {
        browserName = "Opera";
        fullVersion = nAgt.substring(verOffset + 6);
        if ((verOffset = nAgt.indexOf("Version")) != -1)
            fullVersion = nAgt.substring(verOffset + 8);
    }
    // In MSIE, the true version is after "MSIE" in userAgent
    else if ((verOffset = nAgt.indexOf("MSIE")) != -1) {
        browserName = "Microsoft Internet Explorer";
        fullVersion = nAgt.substring(verOffset + 5);
    }
    // In Chrome, the true version is after "Chrome" 
    else if ((verOffset = nAgt.indexOf("Chrome")) != -1) {
        browserName = "Chrome";
        fullVersion = nAgt.substring(verOffset + 7);
    }
    // In Safari, the true version is after "Safari" or after "Version" 
    else if ((verOffset = nAgt.indexOf("Safari")) != -1) {
        browserName = "Safari";
        fullVersion = nAgt.substring(verOffset + 7);
        if ((verOffset = nAgt.indexOf("Version")) != -1)
            fullVersion = nAgt.substring(verOffset + 8);
    }
    // In Firefox, the true version is after "Firefox" 
    else if ((verOffset = nAgt.indexOf("Firefox")) != -1) {
        browserName = "Firefox";
        fullVersion = nAgt.substring(verOffset + 8);
    }
    // In most other browsers, "name/version" is at the end of userAgent 
    else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) <
        (verOffset = nAgt.lastIndexOf('/'))) {
        browserName = nAgt.substring(nameOffset, verOffset);
        fullVersion = nAgt.substring(verOffset + 1);
        if (browserName.toLowerCase() == browserName.toUpperCase()) {
            browserName = navigator.appName;
        }
    }
    // trim the fullVersion string at semicolon/space if present
    if ((ix = fullVersion.indexOf(";")) != -1)
        fullVersion = fullVersion.substring(0, ix);
    if ((ix = fullVersion.indexOf(" ")) != -1)
        fullVersion = fullVersion.substring(0, ix);
 
    majorVersion = parseInt('' + fullVersion, 10);
    if (isNaN(majorVersion)) {
        fullVersion = '' + parseFloat(navigator.appVersion);
        majorVersion = parseInt(navigator.appVersion, 10);
    }
 
    var vpw = Math.max(document.documentElement.clientWidth, window.innerWidth || 0)
    var vph = Math.max(document.documentElement.clientHeight, window.innerHeight || 0)
 
    $(document).ready(function() {
        $('#answer' + SID + 'X' + GID + 'X' + QID).val('' + 'Browser name = ' + browserName + '\n' + 'Full version = ' + fullVersion + '\n' + 'Major version = ' + majorVersion + '\n' + 'navigator.appName = ' + navigator.appName + '\n' + 'navigator.userAgent = ' + navigator.userAgent + '\n' + 'viewport-width = ' + vpw + '\n' + 'viewport-height = ' + vph + '\n');
 
        // hide the question 
        // $('#question'+QID).hide();
 
    });
</script>

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Last edit: 8 years 8 months ago by Ben_V.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 8 months ago #122243 by tpartner
Replied by tpartner on topic Store screen resolution
If all you are concerned about is screen resolution, add a multiple-short-text question with two sub-questions for height and width and insert this script in the question source.

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function() {
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Hide this question
    $(thisQuestion).hide();
 
    // Insert the screen dimensions
    $('input.text:eq(0)', thisQuestion).val(window.screen.width);    
    $('input.text:eq(1)', thisQuestion).val(window.screen.height);
    });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Soparnlin_47063
  • Soparnlin_47063's Avatar Topic Author
  • Offline
  • Banned
  • Banned
More
8 years 8 months ago #122269 by Soparnlin_47063
Replied by Soparnlin_47063 on topic Store screen resolution
Thanks a lot guys! :cheer:

Cheers,
D.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose