获取浏览器数据
1.从其他项目跳转到本项目,在本项目下获取项目跳转来源url
document.referrer
但是也有不可使用的情况
- 直接在浏览器地址栏中输入地址;
- 使用
location.reload()
刷新(location.href
或者location.replace()
刷新有信息); - 在微信对话框中,点击链接进入微信自身的浏览器;
- 扫码进入QQ或者微信的浏览器;
直接新窗口打开一个页面;2017.8.3更新 新版本Chrome测试,新窗口页面依然有document.referrer
- 从https的网站直接进入一个http协议的网站(Chrome下亲测);
a
标签设置rel="noreferrer"
(兼容IE7+);meta
标签来控制不让浏览器发送referer
;
2.获取访问IP、地区、浏览器以及电脑操作系统
- 在index.html中添加搜狐接口的引用
<script src=
"http://pv.sohu.com/cityjson?ie=utf-8"
></script>
- 在js中获取本地id
-
sessionStorage.setItem('ip', returnCitySN["cip"]) sessionStorage.setItem('area', returnCitySN["cname"])
3.新建js文件systemTool.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | // get brower export function GetCurrentBrowser () { let ua = navigator.userAgent.toLocaleLowerCase() let browserType = null if (ua.match(/msie/) != null || ua.match(/trident/) != null ) { browserType = 'IE' } else if (ua.match(/firefox/) != null ) { browserType = 'firefox' } else if (ua.match(/ucbrowser/) != null ) { browserType = 'UC' } else if (ua.match(/opera/) != null || ua.match(/opr/) != null ) { browserType = 'opera' } else if (ua.match(/bidubrowser/) != null ) { browserType = 'baidu' } else if (ua.match(/metasr/) != null ) { browserType = 'sougou' } else if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null ) { browserType = 'QQ' } else if (ua.match(/maxthon/) != null ) { browserType = 'maxthon' } else if (ua.match(/chrome/) != null ) { var is360 = _mime( 'type' , 'application/vnd.chromium.remoting-viewer' ) if (is360) { browserType = '360' } else { browserType = 'chrome' } } else if (ua.match(/safari/) != null ) { browserType = 'Safari' } else { browserType = 'others' } return browserType } function _mime (option, value) { var mimeTypes = navigator.mimeTypes for ( var mt in mimeTypes) { if (mimeTypes[mt][option] === value) { return true } } return false } // get os export function GetOs () { let sUserAgent = navigator.userAgent.toLocaleLowerCase() let isWin = (navigator.platform === 'win32' ) || (navigator.platform === 'windows' ) let isMac = (navigator.platform === 'mac68k' ) || (navigator.platform === 'macppc' ) || (navigator.platform === 'macintosh' ) || (navigator.platform === 'macintel' ) if (isMac) return 'Mac' var isUnix = (navigator.platform === 'x11' ) && !isWin && !isMac if (isUnix) return 'Unix' var isLinux = (String(navigator.platform).indexOf( 'linux' ) > -1) if (isLinux) return 'Linux' if (isWin) { var isWin2K = sUserAgent.indexOf( 'windows nt 5.0' ) > -1 || sUserAgent.indexOf( 'windows 2000' ) > -1 if (isWin2K) return 'Win2000' var isWinXP = sUserAgent.indexOf( 'windows nt 5.1' ) > -1 || sUserAgent.indexOf( 'windows xp' ) > -1 if (isWinXP) return 'WinXP' var isWin2003 = sUserAgent.indexOf( 'windows nt 5.2' ) > -1 || sUserAgent.indexOf( 'windows 2003' ) > -1 if (isWin2003) return 'Win2003' var isWinVista = sUserAgent.indexOf( 'windows nt 6.0' ) > -1 || sUserAgent.indexOf( 'windows vista' ) > -1 if (isWinVista) return 'WinVista' var isWin7 = sUserAgent.indexOf( 'windows nt 6.1' ) > -1 || sUserAgent.indexOf( 'windows 7' ) > -1 if (isWin7) return 'Win7' } if (sUserAgent.indexOf( 'android' ) > -1) return 'Android' if (sUserAgent.indexOf( 'iphone' ) > -1) return 'iPhone' if (sUserAgent.indexOf( 'symbianos' ) > -1) return 'SymbianOS' if (sUserAgent.indexOf( 'windows phone' ) > -1) return 'Windows Phone' if (sUserAgent.indexOf( 'ipad' ) > -1) return 'iPad' if (sUserAgent.indexOf( 'ipod' ) > -1) return 'iPod' return 'others' } // getAddress // {/*<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>*/} // {/*export function GetAddress () {*/} // {/*return returnCitySN*/} // {/*}*/} |
- 使用。在你需要用的vue组件中引用上一步js文件
- import * as sysTool from '../assets/js/systemTool'
- 在data里
-
data () { return { ip: '1.1.1.1', area: '北京市', brower: 'chrome', os: 'windows7' } }
在具体函数中使用
-
12345
this
.ip = sessionStorage.getItem(
'ip'
)
this
.area = sessionStorage.getItem(
'area'
)
this
.brower = sysTool.GetCurrentBrowser()
this
.os = sysTool.GetOs()
console.log(
'ip,地区,浏览器,操作系统,:'
,
this
.ip,
this
.area,
this
.brower,
this
.os)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类