Is this acceptable code to redirect mobile users?

Nov 15, 2010 14:38

After looking through many pages showing fairly large chunks of JS code (of which I am not fluent) I found this very very short code block which appears to work after a quick test from a Desktop and Mobile device. Is this good enough to use for a non-enterprise site?

Thanks for any help! :)

Leave a comment

shanwickoceanic November 16 2010, 23:13:32 UTC
If you understand it and it's good enough, it's good enough. Ultimately, that's what it comes down to. No sense in tearing your hair out if you have something that works.

That said, if the only difference is "an adjusted layout to be more friendly to a tiny screen", you might want to think about whether simply serving a different stylesheet could do the job, removing a whole lot of duplication. In theory, it's as simple as

In practice, you again end up with special cases and other silliness. Iphone in particular tries to be all grown up and ignores the "handheld" stylesheet. There are ways of dealing with that. Or you can take Apple's word for it that Iphone really is that good...

But at least you only have one lot of HTML to deal with, essentially giving you your "simply reformat based on UA". You'd need to try it and see whether the problems outweigh the benefits in your particular case.

Whatever approach you take, it isn't going to be perfect. Even if you do nail every last possibility out there, some lovely company will bring a new phone out next week that breaks it. This is one of several areas where pragmatism trumps perfection. Get it as good as you need to, and don't sweat the rest.

Reply

someprivatetime November 17 2010, 00:31:43 UTC
My CSS is just a hair better then my JS, but in the long run this may make far more sense.

It leads me to ponder further, though, is it possible to use CSS to actually hide things like images or sections in DIV tags? Part of the rearranging, was literally rearranging the page, not just formatting, but removing some DIV tags, replacing 800px header images, etc

Am I likely just thinking of new ways to hang myself?

I'll try playing around with the LINK tags to which you linked, and posted, perhaps I can make something work from there. Much appreciated!

Reply

shanwickoceanic November 17 2010, 15:09:03 UTC
is it possible to use CSS to actually hide things like images or sections in DIV tags? Part of the rearranging, was literally rearranging the page, not just formatting, but removing some DIV tags, replacing 800px header images, etc

CSS can definitely do that, you probably want "display:none". You can have a lot of fun with this stuff (and a lot of pain, but let's not go there for now!). If you haven't seen it before, I recommend a look at http://csszengarden.com/ and the different looks there; the HTML's the same in each case, all that changes are the CSS and the images it calls.

Bear in mind that if you just hide an image it will (IIRC) still be fetched. In other words, if your mobile users are paying for their data they'll still get hit for downloading an image they can't even see. (But they were paying for it before...) You can get around that by using the image as a background, which you'd only specify in your full (not handheld) CSS. Just be aware that you can't give it alt text for accessibility purposes, so you'd only want to do that for images that don't really matter (like pretty banners that add nothing to the content).

Enjoy!

Reply

someprivatetime November 17 2010, 18:46:05 UTC
After quite a bit of fighting with Dreamweaver I think I at least managed to get a basically functional set of LINK tags working. I can see that doing all that I wish to do is going to take quite a bit more learning, but you've managed to point me in the right direction.

Thank you very much!

Reply

shanwickoceanic November 17 2010, 22:40:52 UTC
No problem at all, glad it's been useful. I'm not likely to get too deeply into the technical details of any particular problem - you'll know yourself that the best way through those is usually to figure them out for yourself - but if you find yourself needing a nudge in the right direction just PM me. I think that works, though I've never used it; if not, reply to one of my comments and I'll get an email. I'm in the UK, just so you know roughly when I'm asleep (and probably dreaming in PHP... it's like that at the moment).

One last piece of advice, gained from bitter experience: Dreamweaver. Bin it :) Not right now, but when you're not rushing to complete some project or other, put Dreamweaver to one side, set yourself up with a basic text editor that does syntax colouring, and get comfortable with working that way if you aren't already. (I learned on Notepad because it was all I had, but in 2010 it's just masochistic.) It's far and away the best way to learn what's going on and how it all hangs together, and hand-coding is the only way to be sure that you know what you're actually making. Once you get into the advanced stuff, it can be hard to know what's going on, even for an experienced human; there's no way a dumb piece of software is going to get it, and the last thing you need when IE (it's always IE) isn't playing nicely is some machine's guess at what the HTML should be. I've got war stories about the Dreamweaver messes I've had to sort out. *curls up and begins to rock slowly*

Reply

someprivatetime November 19 2010, 03:29:04 UTC
Thank you for the offer, I may very well take you up on it if I get lost again.

As for hand coding vs a WYSIWYG editor, I'm pleased to say that I hand rolled every page I'd ever made (actually, in a simple editor I wrote for myself back in the stone age of the web) until I got involved with this project. With a few hundred pages, I've grown very fond of the ability to easily manage them, or make a change and have everything auto updated instead of finding dead links every few weeks. And hopefully it'll please you to know that I still go into the Source pane and muck about or clean up the code by hand (and this particular project REALLY needs the "by hand" touch, the guy that made it was learning CSS as he made it, so there are piles of dead code that I'm slowly weeding out[and of course the irony is that _I_ barely know it!]).

I promise I won't heap any Dreamweaver drama on you ... well, maybe, anyway ;)

Between you and hipmaestro I'm feeling quite a bit more confidant that I can get this thing together, thanks a bunch!

Reply


Leave a comment

Up