- Posts: 32
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
collecting browser information
- letty
- Offline
- Junior Member
I tried to adopt the script. I have updated the var ID in the first 3 lines as below.
The browser information is captured. However, the question failed to be hidden in the survey.
Is there anything I have missed?
<script type="text/javascript">
var SID = '818123';
var GID = '3069';
var QID = '121321';
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+;
}
// 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+;
}
// In Firefox, the true version is after "Firefox"
else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
browserName = "Firefox";
fullVersion = nAgt.substring(verOffset+;
}
// 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>
- jelo
- Offline
- Platinum Member
- Posts: 5033
- Thank you received: 1257
letty wrote: // hide the question
//$('#question'+QID).hide();
Remove the comment marker //
$('#question'+QID).hide();
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
- letty
- Offline
- Junior Member
- Posts: 32
- Thank you received: 1
- Mazi
- Offline
- Official LimeSurvey Partner
BTW, instead of setting the survey, group and question ID manually you can simply use this at the beginning of the code:
var SID = '{SID}'; // survey ID
var GID = '{GID}'; // group ID
var QID = '{QID}'; // question ID
Also note that the question type should be "short free text" because when using "long free text" the input field ID is different and no data may get stored. This also depends on the Limesurvey version used.
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
- DenisChenu
- Offline
- LimeSurvey Community Team
- Posts: 13642
- Thank you received: 2491
Can you check if it's OK on demo.sondages.pro/772229 ?Mazi wrote: Thanks for sharing the example. Are there any known reasons why Internet Explorer is stored with "browser name = Netscape"?
Denis
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
- jelo
- Offline
- Platinum Member
- Posts: 5033
- Thank you received: 1257
You see that in your results?Mazi wrote: Thanks for sharing the example. Are there any known reasons why Internet Explorer is stored with "browser name = Netscape"?
The NavigatorID.appName can be Netscape by default (in every browser).
developer.mozilla.org/en-US/docs/Web/API/NavigatorID/appName
The "navigator.userAgent" is relevant.
Beside that:
1. UserAgent can be forged.
2. When it comes to IE, IE forged the useragent to prevent false browser detection (in the haydays of Netscape/Mozilla). And IE had a UA string which caused a lot of cause and was stopped years ago. But older browser might still send a long userstring with crap.
blogs.msdn.microsoft.com/ieinternals/200...tring-use-and-abuse/
A new issue with LS 3?Mazi wrote: Also note that the question type should be "short free text" because when using "long free text" the input field ID is different and no data may get stored. This also depends on the Limesurvey version used.
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
- Mazi
- Offline
- Official LimeSurvey Partner
It is fine there!DenisChenu wrote: Can you check if it's OK on demo.sondages.pro/772229 ?
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
- Mazi
- Offline
- Official LimeSurvey Partner
jelo wrote: You see that in your results?
Exactly!
I was assuming that the stone-old code was just not able to deal with more recent browser agent details.
The issue with the field ID is not related to LS 3 but if that has changed, it must have been quite a while ago. Even at the old 2.06 version I tested, the ID of the textarea of a "long free text" question is different from what the code tries to write to (if I didn't miss anything).
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
- jelo
- Offline
- Platinum Member
- Posts: 5033
- Thank you received: 1257
Which is no surprise, since navigator.appVersion is not used in that demo.Mazi wrote: It is fine there!
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
- DenisChenu
- Offline
- LimeSurvey Community Team
- Posts: 13642
- Thank you received: 2491
No, and never use javascript if server can do it .jelo wrote:
Which is no surprise, since navigator.appVersion is not used in that demo.Mazi wrote: It is fine there!
Use
$_SERVER['HTTP_USER_AGENT']
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.