| checkWidth.js |
function checkWidth() {
if (window.innerWidth < 768) { // 768px works for mobile
window.location.href = "mobile.php"; // The alternate page
}
}
// Run on page load
window.onload = checkWidth;
// Run on window resize
//window.onresize = checkWidth;
Note that the window.onresize = checkWidth; is commented out; It can cause race conditions,
so I don't use it.
Place this in the <head> section of your web page.
| Include |
<script src="assets/checkWidth.js"></script>