jsデバイス情報の取得方法のまとめ
8302 ワード
注:この文章は雪星楓が自慢です.
1.訪問者のIPと所在地を取得する
1.訪問者のIPと所在地を取得する
<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'] + "
: " + returnCitySN['cid'] + "
: " + returnCitySN['cname']);
script>
body>
html>
出力:IP: 61.140.62.124
: 440100
:
2.訪問者の設備情報を取得するspan class="hljs-string">"-//W3C//DTD HTML 4.0 Transitional//EN">
"content-type" content="text/html;charset=utf-8">
javascript
"text/javascript"</span>>
document<span class="hljs-preprocessor">.write</span>(<span class="hljs-string">"userAgent: "</span> + navigator<span class="hljs-preprocessor">.userAgent</span> + <span class="hljs-string">"<br><br>"</span>)<span class="hljs-comment">;</span>
document<span class="hljs-preprocessor">.write</span>(<span class="hljs-string">"appName: "</span> + navigator<span class="hljs-preprocessor">.appName</span> + <span class="hljs-string">"<br><br>"</span>)<span class="hljs-comment">;</span>
document<span class="hljs-preprocessor">.write</span>(<span class="hljs-string">"appCodeName: "</span> + navigator<span class="hljs-preprocessor">.appCodeName</span> + <span class="hljs-string">"<br><br>"</span>)<span class="hljs-comment">;</span>
document<span class="hljs-preprocessor">.write</span>(<span class="hljs-string">"appVersion: "</span> + navigator<span class="hljs-preprocessor">.appVersion</span> + <span class="hljs-string">"<br><br>"</span>)<span class="hljs-comment">;</span>
document<span class="hljs-preprocessor">.write</span>(<span class="hljs-string">"appMinorVersion: "</span> + navigator<span class="hljs-preprocessor">.appMinorVersion</span> + <span class="hljs-string">"<br><br>"</span>)<span class="hljs-comment">;</span>
document<span class="hljs-preprocessor">.write</span>(<span class="hljs-string">"platform: "</span> + navigator<span class="hljs-preprocessor">.platform</span> + <span class="hljs-string">"<br><br>"</span>)<span class="hljs-comment">;</span>
document<span class="hljs-preprocessor">.write</span>(<span class="hljs-string">"cookieEnabled: "</span> + navigator<span class="hljs-preprocessor">.cookieEnabled</span> + <span class="hljs-string">"<br><br>"</span>)<span class="hljs-comment">;</span>
document<span class="hljs-preprocessor">.write</span>(<span class="hljs-string">"onLine: "</span> + navigator<span class="hljs-preprocessor">.onLine</span> + <span class="hljs-string">"<br><br>"</span>)<span class="hljs-comment">;</span>
document<span class="hljs-preprocessor">.write</span>(<span class="hljs-string">"userLanguage: "</span> + navigator<span class="hljs-preprocessor">.language</span> + <span class="hljs-string">"<br><br>"</span>)<span class="hljs-comment">;</span>
document<span class="hljs-preprocessor">.write</span>(<span class="hljs-string">"mimeTypes.description: "</span> + navigator<span class="hljs-preprocessor">.mimeTypes</span>[<span class="hljs-number">1</span>]<span class="hljs-preprocessor">.description</span> + <span class="hljs-string">"<br><br>"</span>)<span class="hljs-comment">;</span>
document<span class="hljs-preprocessor">.write</span>(<span class="hljs-string">"mimeTypes.type: "</span> + navigator<span class="hljs-preprocessor">.mimeTypes</span>[<span class="hljs-number">1</span>]<span class="hljs-preprocessor">.type</span> + <span class="hljs-string">"<br><br>"</span>)<span class="hljs-comment">;</span>
document<span class="hljs-preprocessor">.write</span>(<span class="hljs-string">"plugins.description: "</span> + navigator<span class="hljs-preprocessor">.plugins</span>[<span class="hljs-number">3</span>]<span class="hljs-preprocessor">.description</span> + <span class="hljs-string">"<br><br>"</span>)<span class="hljs-comment">;</span>
出力: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