Chapter 13
Automating Your Sites with JavaScript
In This Chapter
Detecting a user agent and redirecting URLs
Switching CSS external files and selectors
Detecting screen size and switching URL and/or CSS external files and selectors
Validating form fields
For mobile devices, JavaScript can be a real workhorse. It can tell you when the browser looking at your website is a mobile device — and automatically change what appears on the screen, either by changing the URL or changing the CSS. Likewise, JavaScript can determine the screen size of the device — is it a pretty big one, like a tablet, or is it a small one that shares space with a keyboard on a mobile phone? Knowing the size of the screen helps determine the format of the materials you're presenting.
That's not all that JavaScript can do. Little chores such as form validation — and specialized new elements in HTML5 such as <canvas>
— rely heavily on JavaScript. Searches and calculations are possible because JavaScript can compare outcomes with strings and numbers to find matches (or non-matches) and take care of the details for ...
Get HTML, CSS, and JavaScript® Mobile Development For Dummies® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.