This repository has been archived on 2025-12-16. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
word/public/redirect.js
2025-12-16 14:57:51 +01:00

37 lines
1.1 KiB
JavaScript

// Device Detection and Redirect
(function() {
// Check current page
const currentPage = window.location.pathname.split('/').pop() || 'index.html'
// Check if we've already redirected (prevent infinite loops)
const hasRedirected = sessionStorage.getItem('hasRedirected')
if (hasRedirected) {
return
}
// Detect device type
const width = window.innerWidth
const isMobileDevice = /Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
const isTabletDevice = /iPad|Android/i.test(navigator.userAgent) && !isMobileDevice
let targetPage = null
// Determine target page based on device and screen size
if (width < 600 || (isMobileDevice && width < 768)) {
// Mobile: < 600px or mobile device < 768px
targetPage = 'mobile.html'
} else if (width >= 600 && width < 1024) {
// Tablet: 600-1024px
targetPage = 'tablet.html'
} else {
// Desktop: >= 1024px
targetPage = 'index.html'
}
// Redirect if needed
if (currentPage !== targetPage) {
sessionStorage.setItem('hasRedirected', 'true')
window.location.href = targetPage
}
})()