Reputation: 95
I'm trying to re-direct users to the mobile version of my site using this code:
<script>
if ( (screen.width < 800) && (screen.height < 600) ) {
window.location = 'http://yoursite.com/m.asxp';
}
</script>
but the issue is it always re-directs to the homepage. i want the re-direct to go to the same page they came from. for example if they go to yoursite.com/about i want it to re-direct to yoursite.com/m.asxp/about. is this possible?
Upvotes: 2
Views: 87
Reputation: 479
Just replace this:
window.location = 'http://yoursite.com/m.asxp';
with:
window.location = 'http://yoursite.com/m.asxp' + window.location.pathname;
UPD Also you need to change if-condition:
<script>
if (window.location.indexOf('m.asxp') == -1 && (screen.width < 800) && (screen.height < 600) ) {
window.location = 'http://yoursite.com/m.asxp' + window.location.pathname;
}
</script>
Upvotes: 2