Chapter 13

Automating Your Sites with JavaScript

In This Chapter

arrow Detecting a user agent and redirecting URLs

arrow Switching CSS external files and selectors

arrow Detecting screen size and switching URL and/or CSS external files and selectors

arrow 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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.