- Posts: 4
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript"> var SID = '123'; // survey ID var GID = '456'; // group ID var QID = '789'; // question ID 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); } $(document).ready(function() { $('#answer'+SID+'X'+GID+'X'+QID).val('' +'Browser name = '+browserName+'<br>' +'Full version = '+fullVersion+'<br>' +'Major version = '+majorVersion+'<br>' +'navigator.appName = '+navigator.appName+'\n' +'navigator.userAgent = '+navigator.userAgent); // hiding the question $('#question'+QID).hide(); }); </script>
<script type="text/javascript" charset="utf-8"> var SID = '012'; // survey ID var GID = '345'; // group ID var QID = '678'; // question ID $(document).ready(function() { if (screen.width==800||screen.height==600) //if 800x600 {$('#answer'+SID+'X'+GID+'X'+QID+'A1').attr('checked', true);} else if (screen.width==640||screen.height==480) //if 640x480 {$('#answer'+SID+'X'+GID+'X'+QID+'A2').attr('checked', true);} else if (screen.width==1024||screen.height==768) //if 1024x768 {$('#answer'+SID+'X'+GID+'X'+QID+'A3').attr('checked', true);} else //if all else {$('#answer'+SID+'X'+GID+'X'+QID+'A0').attr('checked', true);} // document.limesurvey.submit(); }); </script>
now appreciate that javascript within a question would appear to be the way to go. I had not considered that, nor can I write it, but I am familiar with other basic code so will have a play.
<script type="text/javascript"> var SID = '123'; var GID = '456'; var QID = '789'; jQuery(document).ready(function() { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible myWidth = document.body.clientWidth; myHeight = document.body.clientHeight; } $('#answer'+SID+'X'+GID+'X'+QID).val(myWidth +' X '+ myHeight); }); </script>