JS獲取訪問設備信息的方法

本文將介紹獲取訪問網頁設備的基本信息的方法,提供完整代碼及例子,方便大家使用。

1.獲取訪問者IP及所在地

<!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['cip'] + "<br>地區代碼: " + returnCitySN['cid'] + "<br>所在地: " + returnCitySN['cname']);
  </script>
 </body>
</html>

輸出:

IP: 61.140.62.124
地區代碼: 440100
所在地: 廣東省廣州市


2.獲取訪問者設備信息

<!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>

輸出:

userAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:56.0) Gecko/20100101 Firefox/56.0

appName: Netscape

appCodeName: Mozilla

appVersion: 5.0 (Macintosh)

appMinorVersion: undefined

platform: MacIntel

cookieEnabled: true

onLine: true

userLanguage: zh-CN

mimeTypes.description: Shockwave Flash

mimeTypes.type: application/x-shockwave-flash
發佈了306 篇原創文章 · 獲贊 665 · 訪問量 974萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章