Home > Web Front-end > JS Tutorial > body text

How to get access to device information through JS

jacklove
Release: 2018-06-08 16:04:50
Original
3736 people have browsed it

This article will introduce the method of obtaining basic information of the device accessing the web page, and provide complete code and examples for everyone's convenience.

1. Get the visitor’s IP and location

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
 <head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8">
  <title>javascript获取访问者IP及所在地</title>
  <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
 </head>

 <body>
  <script type="text/javascript">
    document.write("IP: " + returnCitySN[&#39;cip&#39;] + "<br>地区代码: " + returnCitySN[&#39;cid&#39;] + "<br>所在地: " + returnCitySN[&#39;cname&#39;]);  </script>
 </body></html>
Copy after login

Output:

IP: 61.140.62.124地区代码: 440100所在地: 广东省广州市
Copy after login

2. Get the visitor’s device information

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8">
  <title>javascript获取访问者设备信息</title>
 </head>

 <body>
  <script type="text/javascript">
    document.write("userAgent: " + navigator.userAgent + "<br><br>");
    document.write("appName: " + navigator.appName + "<br><br>");
    document.write("appCodeName: " + navigator.appCodeName + "<br><br>");
    document.write("appVersion: " + navigator.appVersion + "<br><br>");
    document.write("appMinorVersion: " + navigator.appMinorVersion + "<br><br>");
    document.write("platform: " + navigator.platform + "<br><br>");
    document.write("cookieEnabled: " + navigator.cookieEnabled + "<br><br>");
    document.write("onLine: " + navigator.onLine + "<br><br>");
    document.write("userLanguage: " + navigator.language + "<br><br>");
    document.write("mimeTypes.description: " + navigator.mimeTypes[1].description + "<br><br>");
    document.write("mimeTypes.type: " + navigator.mimeTypes[1].type + "<br><br>");
    document.write("plugins.description: " + navigator.plugins[3].description + "<br><br>");
  </script>
 </body>
</html>
Copy after login

Output:

userAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:56.0) Gecko/20100101 Firefox/56.0appName: NetscapeappCodeName: MozillaappVersion: 5.0 (Macintosh)appMinorVersion: undefinedplatform: MacIntelcookieEnabled: trueonLine: trueuserLanguage: zh-CNmimeTypes.description: Shockwave FlashmimeTypes.type: application/x-shockwave-flash
Copy after login

This article explains how to obtain access device information through JS. For more related knowledge, please pay attention to the php Chinese website.

Related recommendations:

mysql5.7 export data prompt --secure-file-priv option problem solution

How to pass PHP implements the debug_backtrace method to track code calls

Explains the causes and solutions to the Warning: A non-numeric value encountered problem in PHP

The above is the detailed content of How to get access to device information through JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template