One more set of bug fixes for this original post.
Sometime early this week, Twitter broke some redirection I had been relying on. That is, if I was on my phone, URLs on twitter.com automatically redirected to mobile.twitter.com and kept all my parameters for status and such. mobile.twitter.com had no problem handling the request if I went there explicitly, though.
So here’s the code that lets the phone automatically run to the mobile site, and keeps the PC on the regular site. Yes, it’s browser detection and not feature detection, but I’m the only user, and anyone else wanting to do this kind of thing will probably be similarly relaxed on requirements.
<script type="text/javascript"> // Detects if the current browser is a Palm Pre/Pixi of some sort. Adapted from // http://www.hand-interactive.com/resources/detect-mobile-javascript.htm // Initialize our user agent string to lower case. var devicewebos = "webos"; var uagent = navigator.userAgent.toLowerCase(); function DetectWebOS() { if (uagent.search(devicewebos) > -1) return true; else return false; } function gotostatuspage(message) { // Navigate to the status page, append a pseudo-random number to // trick Twitter into letting us post the same status message // repeatedly. The feed filter will edit out the added number. var d = new Date(); var ms = d.getMilliseconds(); if (DetectWebOS()) { // Twitter didn't like getting redirects from the regular site // to the mobile one, it seems. var urlvar = "http://mobile.twitter.com/home?status="+message+" {"+ms+"}"; } else { var urlvar = "http://twitter.com/home?status="+message+" {"+ms+"}"; } window.location.assign(urlvar); // Refs: // http://stackoverflow.com/questions/743129/mobile-detection-using-javascript // http://stackoverflow.com/questions/1691781/i-need-to-build-my-url-in-a-javascript-function-then-return-the-string-back-to-hr // http://www.w3schools.com/jsref/met_loc_assign.asp } </script>