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/redirect2.js
2025-12-16 18:48:30 +01:00

44 lines
1.3 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 height = window.innerHeight
const userAgent = navigator.userAgent
// Better mobile detection
const isMobilePhone = /iPhone|BlackBerry|IEMobile|Opera Mini/i.test(userAgent)
const isTabletDevice = /iPad|Android(?!.*Mobile)/i.test(userAgent)
let targetPage = null
// Determine target page based on device and screen size
if (width < 400) {
// Mobile phones: detected mobile device < 768px
targetPage = 'mobile.html'
} else if (width < 400) {
// Small screens: force mobile
targetPage = 'mobile.html'
} else if (isTabletDevice || (width >= 500 && width < 1200)) {
// Tablets: iPad/Android tablet OR 500-1200px - use full app
targetPage = 'tablet-app.html'
} else {
// Desktop: >= 1200px
targetPage = 'index.html'
}
// Redirect if needed
if (currentPage !== targetPage) {
sessionStorage.setItem('hasRedirected', 'true')
window.location.href = targetPage
}
})()