I have a site that’s directed toward mobile use. As a result, the
basic structure consists of pages that render exclusively on mobile
devices, and then corresponding pages for desktop browsers that
explain that they need to come back on a mobile device.
Currently, I’m using Javascript on the mobile page to detect browser
width and then it redirects to the desktop page if it’s above 480px
wide.
That works fine, but it’s less than perfect when people link or
bookmark the desktop page, it never redirects back to the mobile one.
And, it seems to be less than perfect for search engines as well.
Here’s what I’ve got now:
index.rhtml renders first and tosses this Javascript at it:
{ winWidth=document.all?document.body.clientWidth:window.innerWidth;
if (winWidth > 481)
location="<%= url_for({:controller => ‘info’, :action =>
‘share_welcome’, :id => @story, :only_path => false, :protocol =>
‘http://’}) %>"
}
So you can see, it directs browsers over a certain width to, in this
case, share_welcome.rhtml
So, in a desktop browser, the index page looks like mysite.com/
share_welcome, while a mobile browser just sees mysite.com
There’s got to be a way to route this browser width logic ahead of
page load so that it’s always mysite.com no matter what, right?
Is it possible to build this into routes.rb somehow?
I’m stumped. Any ideas?
Thanks so much!
Dan