1.产生随机码
function getUUID(){
let sessionID = ''
for (let i = 0
const random = Math.floor(Math.random() * 36)
sessionID += random < 10 ? random : String.fromCharCode(65 + random - 10)
}
return sessionID
}
2.获取页面宽高
function caculatePageSize() {
let xScroll = 0
let yScroll = 0
let windowWidth = 0
let windowHeight = 0
let pageHeight = 0
let pageWidth = 0
if (window.innerHeight && window.scrollMaxY) {
xScroll = window.innerWidth + window.scrollMaxX
yScroll = window.innerHeight + window.scrollMaxY
} else {
if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
xScroll = document.body.scrollWidth
yScroll = document.body.scrollHeight
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth
yScroll = document.body.offsetHeight
}
}
if (self.innerHeight) { // all except Explorer
if (document.documentElement.clientWidth) {
windowWidth = document.documentElement.clientWidth
} else {
windowWidth = self.innerWidth
}
windowHeight = self.innerHeight
} else {
if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth
windowHeight = document.documentElement.clientHeight
} else {
if (document.body) { // other Explorers
windowWidth = document.body.clientWidth
windowHeight = document.body.clientHeight
}
}
}
// for small pages with total height less then height of the viewport
if (yScroll < windowHeight) {
pageHeight = windowHeight
} else {
pageHeight = yScroll
}
// for small pages with total width less then width of the viewport
if (xScroll < windowWidth) {
pageWidth = xScroll
} else {
pageWidth = windowWidth
}
return {
pageWidth,
pageHeight,
windowWidth,
windowHeight,
}
}
3.判断IE浏览器
function IEVersion() {
var userAgent = navigator.userAgent
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1
var isEdge = userAgent.indexOf("Edge") > -1 && !isIE
var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1
if(isIE) {
var reIE = new RegExp("MSIE (\\d+\\.\\d+);")
reIE.test(userAgent)
var fIEVersion = parseFloat(RegExp["$1"])
if(fIEVersion == 7) {
return 7
} else if(fIEVersion == 8) {
return 8
} else if(fIEVersion == 9) {
return 9
} else if(fIEVersion == 10) {
return 10
} else {
return 6
}
} else if(isIE11) {
return 11
} else if(isEdge) {
return 12
}else{
return 13
}
}
export default IEVersion