Resolution Based Redirect
Route traffic by device size. Before responsive CSS was standard, this script was the key to mobile web experiences. It remains useful for directing users to legacy mobile subdomains.
Your current screen width: px
Copy the Script
<script>
var width = screen.width;
if (width <= 600) {
window.location = "http://m.yoursite.com";
} else if (width <= 1024) {
// Optional tablet redirect
// window.location = "http://t.yoursite.com";
} else {
// Stay on desktop site
}
</script>
Frequently Asked Questions
Yes. Modern Responsive Web Design (using CSS Media Queries) is superior because it uses one URL for all devices. Redirects should only be used if you have completely separate mobile/desktop websites (e.g., `m.site.com`).
It depends on your threshold. A width of `800px` usually catches tablets. You can add `else if` conditions to target tablets specifically.
Yes. Resize your browser window and refresh the page to see the script react to the new dimensions.