- Posts: 4
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
collecting browser information
- pomaikai
- Topic Author
- Offline
- New Member
Less
More
11 years 8 months ago #84170
by pomaikai
Replied by pomaikai on topic collecting browser information
OK, I am a plonker !
Should have noticed I was defining the same variable more than once on the same page.
Please ignore last.
Tom
Should have noticed I was defining the same variable more than once on the same page.
Please ignore last.
Tom
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11639
- Thank you received: 2737
11 years 8 months ago #84178
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic collecting browser information
Why do you need to create various scripts anyway? You could put all into one big script, I guess.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.
- letty
- Offline
- Junior Member
Less
More
- Posts: 32
- Thank you received: 1
6 years 5 months ago #160143
by letty
Replied by letty on topic collecting browser information
Thanks for sharing the script.
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>
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>
The topic has been locked.
- jelo
- Offline
- Platinum Member
Less
More
- Posts: 5033
- Thank you received: 1257
6 years 5 months ago #160158
by jelo
Remove the comment marker //
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
Replied by jelo on topic collecting browser information
letty wrote: // hide the question
//$('#question'+QID).hide();
Remove the comment marker //
Code:
$('#question'+QID).hide();
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The following user(s) said Thank You: Ben_V, letty
The topic has been locked.
- letty
- Offline
- Junior Member
Less
More
- Posts: 32
- Thank you received: 1
6 years 5 months ago #160166
by letty
Replied by letty on topic collecting browser information
It works. Many thanks!
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
5 years 4 months ago #178274
by Mazi
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
Replied by Mazi on topic collecting browser information
Thanks for sharing the example. Are there any known reasons why Internet Explorer is stored with "browser name = Netscape"?
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.
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
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13597
- Thank you received: 2487
5 years 4 months ago #178280
by DenisChenu
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.
Replied by DenisChenu on topic collecting browser information
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.
The topic has been locked.
- jelo
- Offline
- Platinum Member
Less
More
- Posts: 5033
- Thank you received: 1257
5 years 4 months ago #178281
by jelo
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/
The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
Replied by jelo on topic collecting browser information
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
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
5 years 4 months ago #178288
by Mazi
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
Replied by Mazi on topic collecting browser information
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
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
5 years 4 months ago #178289
by Mazi
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
Replied by Mazi on topic collecting browser information
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
The topic has been locked.