Client-Side JavaScript
Client-side JavaScript does not exhibit the nonlinear cross-reference problem nearly to the extent that the core language does, and it is possible to learn how to use JavaScript in web browsers in a fairly linear sequence. But you’re probably reading this book to learn client-side JavaScript, and Part II is a long way off, so this section is a quick sketch of basic client-side programming techniques, followed by an in-depth example.
Chapter 13, JavaScript in Web Browsers, is the
first chapter of Part II and it explains in detail how
to put JavaScript to work in web browsers. The most important thing
you’ll learn in that chapter is that JavaScript code can be embedded
within HTML files using the <script> tag:
<html><head><scriptsrc="library.js"></script><!-- include a library of JavaScript code --></head><body><p>This is a paragraph of HTML</p><script>// And this is some client-side JavaScript code// literally embedded within the HTML file</script><p>Here is more HTML.</p></body></html>
Chapter 14, The Window Object, explains techniques for scripting the web browser and covers some important global functions of client-side JavaScript. For example:
<script>functionmoveon(){// Display a modal dialog to ask the user a questionvaranswer=confirm("Ready to move on?");// If they clicked the "OK" button, make the browser load a new pageif(answer)window.location="http://google.com";}// Run the function defined above 1 minute (60,000 milliseconds) ...
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