简体   繁体   English

我如何使用javascript获取有关用户用来从asp.net Web应用程序获取设备的信息?

[英]How can i get information with javascript about the device which the user used to get on my asp.net webapp?

I am working on a WebApp with C# asp.net and i want to get some information about the device of the user which is on my webapp. 我正在使用C#asp.net开发WebApp,我想获取有关Webapp上用户设备的一些信息。 For example the browser, browser version, operating system and os version. 例如浏览器,浏览器版本,操作系统和操作系统版本。 I want to get the information with javascript like it is showed on this page ( https://clientjs.org/ ) but i don't know how to use this with asp.net. 我想用此页面上显示的javascript获取信息( https://clientjs.org/ ),但是我不知道如何在asp.net中使用它。

This will help (from https://medium.com/creative-technology-concepts-code/detect-device-browser-and-version-using-javascript-8b511906745 ): 这将有所帮助(来自https://medium.com/creative-technology-concepts-code/detect-device-browser-and-version-using-javascript-8b511906745 ):

 (function () { 'use strict'; var module = { options: [], header: [navigator.platform, navigator.userAgent, navigator.appVersion, navigator.vendor, window.opera], dataos: [ { name: 'Windows Phone', value: 'Windows Phone', version: 'OS' }, { name: 'Windows', value: 'Win', version: 'NT' }, { name: 'iPhone', value: 'iPhone', version: 'OS' }, { name: 'iPad', value: 'iPad', version: 'OS' }, { name: 'Kindle', value: 'Silk', version: 'Silk' }, { name: 'Android', value: 'Android', version: 'Android' }, { name: 'PlayBook', value: 'PlayBook', version: 'OS' }, { name: 'BlackBerry', value: 'BlackBerry', version: '/' }, { name: 'Macintosh', value: 'Mac', version: 'OS X' }, { name: 'Linux', value: 'Linux', version: 'rv' }, { name: 'Palm', value: 'Palm', version: 'PalmOS' } ], databrowser: [ { name: 'Chrome', value: 'Chrome', version: 'Chrome' }, { name: 'Firefox', value: 'Firefox', version: 'Firefox' }, { name: 'Safari', value: 'Safari', version: 'Version' }, { name: 'Internet Explorer', value: 'MSIE', version: 'MSIE' }, { name: 'Opera', value: 'Opera', version: 'Opera' }, { name: 'BlackBerry', value: 'CLDC', version: 'CLDC' }, { name: 'Mozilla', value: 'Mozilla', version: 'Mozilla' } ], init: function () { var agent = this.header.join(' '), os = this.matchItem(agent, this.dataos), browser = this.matchItem(agent, this.databrowser); return { os: os, browser: browser }; }, matchItem: function (string, data) { var i = 0, j = 0, html = '', regex, regexv, match, matches, version; for (i = 0; i < data.length; i += 1) { regex = new RegExp(data[i].value, 'i'); match = regex.test(string); if (match) { regexv = new RegExp(data[i].version + '[- /:;]([\\\\d._]+)', 'i'); matches = string.match(regexv); version = ''; if (matches) { if (matches[1]) { matches = matches[1]; } } if (matches) { matches = matches.split(/[._]+/); for (j = 0; j < matches.length; j += 1) { if (j === 0) { version += matches[j] + '.'; } else { version += matches[j]; } } } else { version = '0'; } return { name: data[i].name, version: parseFloat(version) }; } } return { name: 'unknown', version: 0 }; } }; var e = module.init(), debug = ''; debug += 'os.name = ' + e.os.name + '<br/>'; debug += 'os.version = ' + e.os.version + '<br/>'; debug += 'browser.name = ' + e.browser.name + '<br/>'; debug += 'browser.version = ' + e.browser.version + '<br/>'; debug += '<br/>'; debug += 'navigator.userAgent = ' + navigator.userAgent + '<br/>'; debug += 'navigator.appVersion = ' + navigator.appVersion + '<br/>'; debug += 'navigator.platform = ' + navigator.platform + '<br/>'; debug += 'navigator.vendor = ' + navigator.vendor + '<br/>'; document.getElementById('log').innerHTML = debug; }()); 
 <div id="log"></div> 

You can get info about device in window. 您可以在窗口中获取有关设备的信息。 navigator and window.location objects. 导航器和window.location对象。

If you want to get control over device capabilities see this 如果要控制设备功能, 请参阅此

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Facebook登录后,如何在asp.net应用程序中使用javascript SDK获取用户信息 - After facebook login how to get User Information using javascript SDK in asp.net application 如何使用Javascript调试来使用我的ASP.NET MVC应用程序? - How can I get Javascript debugging to work with my ASP.NET MVC application? 如何在asp.net cshtml文件中获取我的JavaScript代码? - How can I get my javascript work in an asp.net cshtml file? javascript中如何获取设备信息和浏览器信息? - How can i get device information and browser information in javascript? 如何从基于只有一个asp.net形式的母版页的asp.net页中的javascript获取价值 - How to get value from javascript in asp.net page based on masterpage which can have only one asp.net form 如何使用JavaScript在样式表中获取有关图像的信息 - How can I get information about images in a stylesheet using JavaScript 如何将 javascript 加载到最初可能隐藏在 ASP.NET 中的控件上? - How do I get javascript onto a control which might be initially hidden in ASP.NET? 如何使用JavaScript变量在JavaScript函数中获取ASP.NET ClientID? - How can I use a JavaScript variable to get an ASP.NET ClientID inside a JavaScript function? 我可以使用javascript和google-analytics获得有关用户地理位置的信息吗? - Can I get information about user's geolocation using javascript and google-analytics? 如何使用JavaScript从ASP.Net MVC中的表单获取“验证消息”的值? - How can I get the value of Validation Message from form in ASP.Net MVC, using javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM