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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access